DocumentBase.TablesOfContents 属性

获取一个 TablesOfContents 集合,该集合表示文档的目录。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v4.0.Utilities(在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

语法

声明
Public ReadOnly Property TablesOfContents As TablesOfContents
public TablesOfContents TablesOfContents { get; }

属性值

类型:Microsoft.Office.Interop.Word.TablesOfContents
一个 TablesOfContents 集合,表示文档的目录。

示例

下面的代码示例向文档添加两个段落并向这两个段落分配“标题 1”和“标题 2”样式。 该代码然后在插入点创建一个仅包括样式为“标题 1”的段落的目录。 若要使用此示例,请从文档级项目内的 ThisDocument 类中运行此示例。

Private Sub DocumentTablesOfContents()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "Heading 1"
    Me.Paragraphs(2).Range.Text = "Heading 2"

    Dim Style1 As Object = Word.WdBuiltinStyle.wdStyleHeading1
    Me.Paragraphs(1).Style = Style1

    Dim Style2 As Object = Word.WdBuiltinStyle.wdStyleHeading2
    Me.Paragraphs(2).Style = Style2

    Dim HeadingLevel As Object = 1
    Me.TablesOfContents.Add(Me.Application.Selection.Range, , HeadingLevel, _
        HeadingLevel)
End Sub 
private void DocumentTablesOfContents()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "Heading 1";
    this.Paragraphs[2].Range.Text = "Heading 2";

    object Style1 = Word.WdBuiltinStyle.wdStyleHeading1;
    this.Paragraphs[1].set_Style(ref Style1);

    object Style2 = Word.WdBuiltinStyle.wdStyleHeading2;
    this.Paragraphs[2].set_Style(ref Style2);

    object HeadingLevel = 1;
    this.TablesOfContents.Add(this.Application.Selection.Range,
        ref missing, ref HeadingLevel, ref HeadingLevel,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing);
}

.NET Framework 安全性

请参见

参考

DocumentBase 类

Microsoft.Office.Tools.Word 命名空间