API Reference
Find-OfficeWordTable
Finds Word tables containing matching cell text.
Remarks
Searches table cell paragraphs in a Word document and returns the matching WordTable objects. Use this when a document came from a template or another system and the script needs to locate a table by visible marker text before appending rows, changing cells, or applying table-cell formatting. By default only top-level tables are searched. Use -IncludeNested to include tables inside table cells. Use -Text for literal contains matching or -Pattern for regular expressions.
Examples
Find the table that contains a marker and append a row.
PS>
$doc = Get-OfficeWord -Path .\Report.docx
$table = Find-OfficeWordTable -Document $doc -Text 'Risk register' | Select-Object -First 1
$table | Add-OfficeWordTableRow -Values 'Contoso', 'Open', 'High'
Searches table cell paragraphs and returns the matching OfficeIMO table object.
Find a risk table, append a row, and update a status cell.
PS>
$doc = Get-OfficeWord -Path .\Handover.docx
$table = Find-OfficeWordTable -Document $doc -Text 'Risk marker' | Select-Object -First 1
$table | Add-OfficeWordTableRow -Values 'Mitigation plan', 'Service Desk', 'Ready'
$table | Get-OfficeWordTableCell -Row 2 -Column 2 |
Set-OfficeWordTableCell -Text 'Investigating' -ShadingFillColor '#fff2cc' -ShadingPattern Clear
$doc | Close-OfficeWord -Save
Shows the common existing-document workflow: locate the table, mutate it, then save the open document.
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.
Syntax
Find-OfficeWordTable [-CaseSensitive] [-IncludeNested] -InputPath <String> -Text <String> [<CommonParameters>]#PathTextParameters
- CaseSensitive SwitchParameter
- Use case-sensitive matching.
- IncludeNested SwitchParameter
- Include nested tables inside table cells.
- InputPath String
- Path to the document to open read-only for searching.
- Text String
- Literal text to find in table cells.
Outputs
OfficeIMO.Word.WordTable
Find-OfficeWordTable [-CaseSensitive] [-IncludeNested] -InputPath <String> -Pattern <String> [<CommonParameters>]#PathRegexParameters
- CaseSensitive SwitchParameter
- Use case-sensitive matching.
- IncludeNested SwitchParameter
- Include nested tables inside table cells.
- InputPath String
- Path to the document to open read-only for searching.
- Pattern String
- Regular expression pattern to find in table cells.
Outputs
OfficeIMO.Word.WordTable
Find-OfficeWordTable [-CaseSensitive] -Document <WordDocument> [-IncludeNested] -Text <String> [<CommonParameters>]#DocumentTextParameters
- CaseSensitive SwitchParameter
- Use case-sensitive matching.
- Document WordDocument
- Open document to inspect. The caller controls the document lifetime.
- IncludeNested SwitchParameter
- Include nested tables inside table cells.
- Text String
- Literal text to find in table cells.
Outputs
OfficeIMO.Word.WordTable
Find-OfficeWordTable [-CaseSensitive] -Document <WordDocument> [-IncludeNested] -Pattern <String> [<CommonParameters>]#DocumentRegexParameters
- CaseSensitive SwitchParameter
- Use case-sensitive matching.
- Document WordDocument
- Open document to inspect. The caller controls the document lifetime.
- IncludeNested SwitchParameter
- Include nested tables inside table cells.
- Pattern String
- Regular expression pattern to find in table cells.
Outputs
OfficeIMO.Word.WordTable