You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Novacode;
  6. using System.Drawing;
  7. namespace ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // Create a new document.
  14. using (DocX document = DocX.Create(@"Test.docx"))
  15. {
  16. // Add Headers to the document.
  17. document.AddHeaders();
  18. // Get the default Header.
  19. Header header = document.Headers.odd;
  20. // Insert a Paragraph into the Header.
  21. Paragraph p0 = header.InsertParagraph();
  22. // Append place holders for PageNumber and PageCount into the Header.
  23. // Word will replace these with the correct value foreach Page.
  24. p0.Append("Page (");
  25. p0.AppendPageNumber(PageNumberFormat.normal);
  26. p0.Append(" of ");
  27. p0.AppendPageCount(PageNumberFormat.normal);
  28. p0.Append(")");
  29. p0.ReplaceText("Page (", "Monster <");
  30. p0.ReplaceText(")", ">");
  31. // Save the document.
  32. document.Save();
  33. }
  34. }
  35. }
  36. }