2
我使用vb.net命名空間「Imports Microsoft.Office.Interop.Word」。我有文字文檔,我想在這些文檔中創建頁眉和/或頁腳。例如,「Date:[CurrentDate] Page:[CurrentPage]」等頁腳。目前我只寫了一個成功的領域。如果我寫/添加下一個字段,第一個字段將被刪除。像「替換」而不是「添加」。代碼有什麼問題?如何通過vb.net在單詞標題/頁腳中插入多個然後一個項目?
For Each section As Section In _wordDoc.Application.ActiveDocument.Sections
Dim footerRange As Range = section.Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
footerRange.Fields.Add(footerRange, WdFieldType.wdFieldFileName)
footerRange.Fields.Add(footerRange, WdFieldType.wdFieldDate)
' footerRange.Fields.Add(footerRange, "Page")
footerRange.Fields.Add(footerRange, WdFieldType.wdFieldPage)
'footerRange.Fields.Add(footerRange, "-")
footerRange.Fields.Add(footerRange, WdFieldType.wdFieldNumPages)
footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight
Next
第二個問題是,如何添加簡單的文本到頁眉/頁腳?
我想,我一定要插入類似 「footerrange.collapse()」。但我不知道如何處理,以獲得正確的解決方案。 – Cit 2014-12-19 10:22:18