Cmdlet
Update-OfficeWordTableOfContents
Updates the table of contents in a Word document.
Syntax
Examples
Mark table of contents for refresh on open.
New-OfficeWord -Path .\ExecutiveReport.docx {
Add-OfficeWordTableOfContents
Add-OfficeWordParagraph -Text 'Executive summary' -Style Heading1
Add-OfficeWordParagraph -Text 'Summary text'
Update-OfficeWordTableOfContents
}Marks TOC fields as dirty and updates the document settings so Word refreshes the TOC when opened.
Regenerate a TOC in an existing document object.
$doc = Get-OfficeWord -Path .\Report.docx
$doc | Update-OfficeWordTableOfContents -Regenerate
$doc | Save-OfficeWord -Path .\Report-RegeneratedToc.docxUses OfficeIMO's regenerate path, then saves the updated document.
Parameters
- -Document WordDocument
- Document to update when provided explicitly.
- -PassThru SwitchParameter
- Emit the updated table of contents.
- -Regenerate SwitchParameter
- Rebuild the table of contents before updating.
- -TableOfContents WordTableOfContent
- Table of contents to update.
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.