Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Set-OfficeWordTableOfContents

Module PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument OfficeIMO.Word.WordTableOfContent
Outputs
OfficeIMO.Word.WordTableOfContent

Sets properties on a table of contents in a Word document.

Syntax

Set-OfficeWordTableOfContents [-PassThru] [-TableOfContents <WordTableOfContent>] [-Text <String>] [-TextNoContent <String>] [<CommonParameters>]
#
Parameter set: TableOfContents
Set-OfficeWordTableOfContents [-Document <WordDocument>] [-PassThru] [-Text <String>] [-TextNoContent <String>] [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Customize table of contents text during composition.

New-OfficeWord -Path .\Report.docx {
    Add-OfficeWordTableOfContents
    Set-OfficeWordTableOfContents -Text 'Contents' -TextNoContent 'No entries yet'
    Add-OfficeWordParagraph -Text 'Executive summary' -Style Heading1
    Update-OfficeWordTableOfContents
}

Updates TOC display text, adds heading content, and marks the TOC for refresh.

Update an existing TOC object from a document.

$doc = Get-OfficeWord -Path .\Report.docx
$doc |
    Get-OfficeWordTableOfContents |
    Set-OfficeWordTableOfContents -Text 'Report contents'
$doc | Save-OfficeWord -Path .\Report-Toc.docx

Pipes the OfficeIMO TOC object into the thin setter and saves the document.

Parameters

-PassThru SwitchParameter optional
Emit the updated table of contents.
-TableOfContents WordTableOfContent optionalpipeline: True (ByValue)sets: TableOfContents
Table of contents to update.
-Text String optional
Heading text for the table of contents.
-TextNoContent String optional
Text shown when the table of contents has no entries.
-Document WordDocument optionalpipeline: True (ByValue)sets: Document
Document to update when provided explicitly.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.