This topic describes the TablesOfContents APIs for Word documents.
TablesOfContents
ActiveDocument.TablesOfContents
Retrieves all tables of contents in the document.
This feature is supported in the JavaScript software development kit (SDK) V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContentsexpression: An application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all tables of contents in the document. const tablesOfContents = await app.ActiveDocument.TablesOfContents; }
Methods
ActiveDocument.TablesOfContents.Add()
To insert a folder, use the Add() method.
This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Add({ Range })expression: An application object for the document type.
Parameters
Property
Data type
Required
Description
Range
Object
Yes
The area to insert the table of contents. Set the following properties:
Start: The starting point of the table of contents. The data type is Number.
End: The ending point of the table of contents. The data type is Number.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); }
Properties
ActiveDocument.TablesOfContents.Count
Retrieves the total number of tables of contents in the document.
This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Countexpression: An application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); // Get the total number of tables of contents in the document. await app.ActiveDocument.TablesOfContents.Count; }
TableOfContents
ActiveDocument.TablesOfContents.Item()
Retrieves a single table of contents object from the document.
TableOfContentsandTablesOfContentsare two different objects. `TableOfContents` represents a single table of contents, and `TablesOfContents` represents a collection of tables of contents. A document can contain more than one table of contents.This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Item(Index)expression: An application object for the document type.
Parameters
Property
Data type
Required
Description
Index
Number
Yes
The index of the table of contents.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); // Get a single table of contents object. await app.ActiveDocument.TablesOfContents.Item(1); }
Methods
ActiveDocument.TablesOfContents.Item(Index).Update()
You can use the Update() method to update the entire directory object.
This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Item(Index).Update()expression: An application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); // Update the entire table of contents. await app.ActiveDocument.TablesOfContents.Item(1).Update(); }
ActiveDocument.TablesOfContents.Item(Index).UpdatePageNumbers()
Updates only the page numbers in the table of contents.
This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Item(Index).UpdatePageNumbers()expression: An application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); // Update only the page numbers. await app.ActiveDocument.TablesOfContents.Item(1).UpdatePageNumbers(); }
ActiveDocument.TablesOfContents.Item(Index).SetStyles()
Sets the style of the table of contents.
This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Item(Index).SetStyles(LowerHeadingLevel, IncludePageNumbers, TabLeader)expression: An application object for the document type.
Parameters
Property
Data type
Required
Description
LowerHeadingLevel
Number
No
The display level. The value can be an integer from 1 to 9.
IncludePageNumbers
Boolean
No
Specifies whether to show page numbers. Valid values are:
true (default): Yes.
false: No.
TabLeader
Number
No
The type of tab leader character. For more information, see WdTabLeader.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); // Set the style of the table of contents. const tabLeader = app.Enum.WdTabLeader.wdTabLeaderDashes await app.ActiveDocument.TablesOfContents.Item(1).SetStyles(9, true, tabLeader) }
ActiveDocument.TablesOfContents.Item(Index).Delete()
You can use the Delete() method to delete a folder.
This feature is supported in the JavaScript SDK V1.1.12 and later.
This feature is available for PC clients only.
Syntax
expression.ActiveDocument.TablesOfContents.Item(Index).Delete()expression: An application object for the document type.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get the Range object. const range = await app.ActiveDocument.Range(0, 0); // Insert a table of contents. await app.ActiveDocument.TablesOfContents.Add(range); // Delete the table of contents. await app.ActiveDocument.TablesOfContents.Item(1).Delete(); }