2013-07-09 39 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

我編輯了答案 –