How to add title with .NetOffice library

I use NetOffice to create Word documents.

There is a little documentation, and I'm trying to add a title. Can anyone help?

+4
source share
1 answer

You should use the Word.Section.Headers property, in the example below I put the image aligned to the right in 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 use of text:

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

Hope this helps to research further.

+3
source

Source: https://habr.com/ru/post/1490454/


All Articles