Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var myCustomProperty = "MyCustomProperty";
- foreach (Microsoft.Office.Interop.Word.Section section in Document.Sections)
- {
- var headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
- foreach(Word.Field field in headerRange.Fields)
- {
- if(field.Type == Word.WdFieldType.wdFieldDocProperty
- && field.Code.Text.Contains(myCustomProperty))
- {
- //already has the header
- break;
- }
- }
- headerRange.Collapse(Word.WdCollapseDirection.wdCollapseStart);
- var f = (Word.Field)headerRange.Fields.Add(headerRange,
- Word.WdFieldType.wdFieldDocProperty,
- myCustomProperty,
- true);
- f.Code.Font.Name = this.FontName;
- f.Code.Font.Size = this.FontSize;
- f.Code.Font.Bold = (int)this.IsBold;
- f.Code.Font.Italic = (int)this.IsItalic;
- f.Code.HighlightColorIndex = Word.WdColorIndex.wdYellow;
- f.Update();
- f.Code.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
- f.Code.InsertParagraphAfter();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement