2014-09-24 48 views
1

我在下面列出了目錄代碼。我需要把它放在我的文檔的第二頁上。該文件長15頁。要將它插入第二頁,我將不得不在第一頁末尾添加一個分頁符,然後在第二頁上插入目錄表。在Word文檔的開頭插入目錄

如何將它放在文檔的第二頁上?我知道它的範圍,但我很確定如何做到這一點。

目錄的代碼如下。

object oTrueValue = true; 
     object start = oWord.ActiveDocument.Content.End - 1; 

     Word.Range rangeForTOC = oDoc.Range(ref start, ref oMissing); 
     Word.TableOfContents toc = oDoc.TablesOfContents.Add(rangeForTOC, ref oTrueValue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrueValue); 
     toc.Update(); 

     Word.Range rngTOC = toc.Range; 
     rngTOC.Font.Size = 12; 
     rngTOC.Font.Name = "Arial"; 
     rngTOC.Font.Bold = 0; 

回答

1

轉到第一頁的末尾,然後添加一個分頁符,然後通過TOC:

// Go to end of document 
Object what = WdGoToItem.wdGoToLine; 
Object which = WdGoToDirection.wdGoToLast; 
wordApp.Selection.GoTo(what, which, ref missing, ref missing); 

插入分頁符:

`selection.TypeText("\f");//page break` 

創建的ToC:

selection.Font.Bold = 1; 
selection.TypeText("Table of Content\n"); 
TableOfContents toc = wordDoc.TablesOfContents.Add(selection.Range, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); 
}//if