Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Novacode;
  6. using System.Text.RegularExpressions;
  7. using System.IO;
  8. namespace StringReplaceTestApp
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. File.Copy(@"Test.docx", "Manipulated.docx", true);
  15. // Load the document that you want to manipulate
  16. DocX document = DocX.Load(@"Manipulated.docx");
  17. // Loop through the paragraphs in the document
  18. foreach (Paragraph p in document.Paragraphs)
  19. {
  20. /*
  21. * Replace each instance of the string pear with the string banana.
  22. * Specifying true as the third argument informs DocX to track the
  23. * changes made by this replace. The fourth argument tells DocX to
  24. * ignore case when matching the string pear.
  25. */
  26. p.Replace("pear", "banana", true, RegexOptions.IgnoreCase);
  27. }
  28. // File will be saved to \StringReplaceTestApp\bin\Debug
  29. document.Save();
  30. }
  31. }
  32. }