5

I'm using NetOffice to create Word documents.

There is little documentation and I'm struggling to add a header. Can anybody help?

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Hazel
  • 141
  • 1
  • 2
  • 10
  • What do you mean by _header_? If you mean a matter of font size/color/boldness/ecc.. you can play with the `Selection` property of a `Word.Application` object – Tobia Zambon Jul 09 '13 at 09:29
  • like add a header to document so it appears on each page. – Hazel Jul 09 '13 at 09:33

1 Answers1

4

You have to use the Word.Section.Headers property, in the example below I've put an image right-aligned on the page header

    foreach (Word.Section section in newDocument.Sections)
        {
            string picturePath = @"D:\Desktop\test.png";
            section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.InlineShapes.AddPicture(picturePath);
            section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
        }

To add some text use:

    foreach (Word.Section section in newDocument.Sections)
       section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "TEST";

Hope this helps to investigate further.

Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69