Nelogeek

Untitled

Nov 10th, 2021
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using Word = Microsoft.Office.Interop.Word;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Word.Application app = new Word.Application();
  9.         Object fileName = @"D:\тест.docx";
  10.         Object missing = Type.Missing;
  11.         app.Documents.Open(ref fileName);
  12.         Word.Find find = app.Selection.Find;
  13.         find.Text = "<NAME>";
  14.         find.Replacement.Text = "ТВОЙ ТЕКСТ ДЛЯ ВСТАВКИ";
  15.         Object wrap = Word.WdFindWrap.wdFindContinue;
  16.         Object replace = Word.WdReplace.wdReplaceAll;
  17.         find.Execute(FindText: Type.Missing,
  18.             MatchCase: false,
  19.             MatchWholeWord: false,
  20.             MatchWildcards: false,
  21.             MatchSoundsLike: missing,
  22.             MatchAllWordForms: false,
  23.             Forward: true,
  24.             Wrap: wrap,
  25.             Format: false,
  26.             ReplaceWith: missing, Replace: replace);
  27.         app.ActiveDocument.Save();
  28.         app.ActiveDocument.Close();
  29.         app.Quit();      
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment