2017-06-06 66 views
0

使用下面提供的代碼,當我按下按鈕時,頁面被編號。但是,如果我選擇了第一頁以外的任何頁面,則頁碼成爲起始頁碼,即,在選擇頁面2時單擊該按鈕將頁面1上的號碼設置爲「2」。我怎麼能在任何情況下從第一頁開始。如何在microsoft interop中更改word中的起始頁碼?

Microsoft.Office.Interop.Word.Document Doc = //Gets current Document 
oject CurrentPage = Microsoft.Office.Interop.Word.WdFieldType.wdFieldNumPages; 
object oMissing = System.Reflection.Missing.Value; 
//Gets the Header 
Doc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 
//Adds the page number 
Doc.ActiveWindow.Selection.Fields.Add(
Doc.ActiveWindow.Selection.Range, ref CurrentPage, ref oMissing, ref oMissing); 

回答

0

對象HeaderFooter包含一個PageNumbers屬性,它有幾個有趣的屬性,包括StartingNumber。

有關如何檢索正確的HeaderFooter實例的一些信息,請參閱here

+0

這就是我在C#中找到的東西。我只是不確定「我」和「我」是什麼。 'Doc.ActiveWindow.Selection.Sections [i] .Headers [j] .PageNumbers.StartingNumber = 1;' –

+0

我的猜測是ActiveDocument.Sections [1] .Footers [wdHeaderFooterPrimary] .PageNumber s.StartingNumber = 1; 如果你的文檔有幾個部分,我會說在相應的部分設置起始編號循環。您可能需要根據您的文檔對第一部分的章節做一些特殊處理:(請參閱https://msdn.microsoft.com/zh-cn/library/office/ff194465.aspx) 您是否嘗試過玩數字? – misterfrb

+0

我正在通過for循環運行所有數字,但除了「System.Runtime.InteropServices.COMException」之外沒有任何事情發生。 –

相關問題