2013-07-09 32 views
4

我正在使用NetOffice来创建Word文档。如何添加标头.NetOffice库

几乎没有文档,我正在努力添加标题。任何人都可以帮忙吗?

+0

_header_是什么意思?如果你的意思是字体大小/颜色/粗体/ ecc ..你可以使用'Word.Application'对象的''Selection'属性来玩 –

+0

,比如向文档中添加一个标题,以便它出现在每个页面上。 – Hazel

回答

3

您必须使用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"; 

希望这有助于进一步调查。

+0

谢谢。我如何添加文本? – Hazel

+1

我编辑了答案 –