I'm using NetOffice to create Word documents.
There is little documentation and I'm struggling to add a header. Can anybody help?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With