我正在使用NetOffice创建Word文档。
由于缺乏文档,我无法很好地添加页眉。有人能帮忙吗?
您需要使用Word.Section.Headers
属性,在下面的示例中,我已将图像右对齐于页面页眉上。
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;
}
要添加一些文本,请使用:
foreach (Word.Section section in newDocument.Sections)
section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "TEST";
Word.Application
对象的Selection
属性进行调整。 - Tobia Zambon