Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Get-OfficeWordTableOfContents

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

Gets the table of contents from a Word document.

Syntax

Get-OfficeWordTableOfContents [-Path] <String> [<CommonParameters>]
#
Parameter set: Path
Get-OfficeWordTableOfContents -Document <WordDocument> [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Read a table of contents before updating it.

$doc = Get-OfficeWord -Path .\Report.docx
$toc = $doc | Get-OfficeWordTableOfContents
if ($toc) {
    $toc | Set-OfficeWordTableOfContents -Text 'Contents' -TextNoContent 'No entries' -PassThru
    $doc | Save-OfficeWord -Path .\Report-Toc.docx
}

Gets the TOC from an open document, updates it, and saves a variant.

Parameters

-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path
Path to the .docx file.
-Document WordDocument requiredpipeline: True (ByValue)sets: Document
Word document to read.

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.