Share via


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 命名空間