Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
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

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.