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

Add-OfficeWordTableOfContents

Aliases: WordTableOfContents
Module
PSWriteOffice
Aliases
WordTableOfContents
Inputs
OfficeIMO.Word.WordDocument
Outputs
OfficeIMO.Word.WordTableOfContent

Adds a table of contents to a Word document.

Syntax

Add-OfficeWordTableOfContents
[-Document <WordDocument>]
[-PassThru]
[-Style <Template1|Template2>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Examples

Add a table of contents before report sections.

New-OfficeWord -Path .\ExecutiveReport.docx {
    Add-OfficeWordTableOfContents -Style Template1
    Add-OfficeWordParagraph -Text 'Executive summary' -Style Heading1
    Add-OfficeWordParagraph -Text 'Summary text'
    Add-OfficeWordParagraph -Text 'Appendix' -Style Heading1
    Add-OfficeWordParagraph -Text 'Supporting details'
    Update-OfficeWordTableOfContents
}

Creates a navigable report outline and marks the TOC for refresh when the document opens.

Parameters

-Document WordDocument optionalpipeline: True (ByValue)
Document to modify when provided explicitly.
-PassThru SwitchParameter optional
Emit the created table of contents.
-Style WordTableOfContentsStyle optional
Table of contents template style.
Possible values: Template1, Template2

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.