【问题标题】:Insert Table Of Contents at the beginning of Word Document在 Word 文档开头插入目录
【发布时间】:2014-11-19 13:35:02
【问题描述】:

我有下面的目录代码。我需要把它放在我文件的第二页上。该文件有 15 页长。要将其插入第二页,我必须在第一页的末尾添加一个分页符,然后将目录插入到第二页。

我怎样才能把它放在文档的第二页?我知道它的范围,但我知道如何做到这一点。

目录代码如下。

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;

【问题讨论】:

    标签: c# .net ms-word office-interop tableofcontents


    【解决方案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`
    

    创建目录:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多