문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top