# Set-OfficeWordTableOfContents

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

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Word.WordDocument` `OfficeIMO.Word.WordTableOfContent`

**Outputs**

`OfficeIMO.Word.WordTableOfContent`

**Source**

[SetOfficeWordTableOfContentsCommand.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Word/SetOfficeWordTableOfContentsCommand.cs#L31) 

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

## Syntax

```
Set-OfficeWordTableOfContents
[-Document <WordDocument>]
[-PassThru]
[-Text <String>]
[-TextNoContent <String>]
[<CommonParameters>]
```

[#](#method-set-officewordtableofcontents-worddocument-switchparameter-string-string)

Parameter set: `Document`

```
Set-OfficeWordTableOfContents
[-PassThru]
-TableOfContents <WordTableOfContent>
[-Text <String>]
[-TextNoContent <String>]
[<CommonParameters>]
```

[#](#method-set-officewordtableofcontents-switchparameter-wordtableofcontent-string-string)

Parameter set: `TableOfContents`

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Add a Table of Contents and Fields in Word](/docs/word/fields-toc/) Guide
  
  Insert a table of contents, page, date and property fields into DOCX files, refresh them on open or in code, and read fields with OfficeIMO.Word.

## Examples

### Customize table of contents text during composition.

```powershell
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.

```powershell
$doc = Open-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

**-Document WordDocument optionalpipeline: True (ByValue)sets: Document**

Document to update when provided explicitly.

**-PassThru SwitchParameter optional**

Emit the updated table of contents.

**-Text String optional**

Heading text for the table of contents.

**-TextNoContent String optional**

Text shown when the table of contents has no entries.

**-TableOfContents WordTableOfContent requiredpipeline: True (ByValue)sets: TableOfContents**

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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:75E1E6376DE6CBE9FB2608D466F2659679A5F2D06EE7823F6AD50B266852F6CE -->
