Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. var myCustomProperty = "MyCustomProperty";
  2. foreach (Microsoft.Office.Interop.Word.Section section in Document.Sections)
  3. {
  4. var headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
  5. foreach(Word.Field field in headerRange.Fields)
  6. {
  7. if(field.Type == Word.WdFieldType.wdFieldDocProperty
  8. && field.Code.Text.Contains(myCustomProperty))
  9. {
  10. //already has the header
  11. break;
  12. }
  13. }
  14. headerRange.Collapse(Word.WdCollapseDirection.wdCollapseStart);
  15. var f = (Word.Field)headerRange.Fields.Add(headerRange,
  16. Word.WdFieldType.wdFieldDocProperty,
  17. myCustomProperty,
  18. true);
  19.  
  20. f.Code.Font.Name = this.FontName;
  21. f.Code.Font.Size = this.FontSize;
  22. f.Code.Font.Bold = (int)this.IsBold;
  23. f.Code.Font.Italic = (int)this.IsItalic;
  24. f.Code.HighlightColorIndex = Word.WdColorIndex.wdYellow;
  25. f.Update();
  26. f.Code.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
  27. f.Code.InsertParagraphAfter();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement