Find-OfficeWordTable
Finds Word tables containing matching cell text.
Syntax
Find-OfficeWordTable [-CaseSensitive] [-IncludeNested] [-Path] <String> [-Text] <String> [<CommonParameters>]#PathTextFind-OfficeWordTable [-CaseSensitive] [-IncludeNested] [-Path] <String> [-Pattern] <String> [<CommonParameters>]#PathRegexFind-OfficeWordTable [-CaseSensitive] -Document <WordDocument> [-IncludeNested] [-Text] <String> [<CommonParameters>]#DocumentTextFind-OfficeWordTable [-CaseSensitive] -Document <WordDocument> [-IncludeNested] [-Pattern] <String> [<CommonParameters>]#DocumentRegexDescription
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.
$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.
$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 -SaveShows the common existing-document workflow: locate the table, mutate it, then save the open document.
Parameters
- -CaseSensitive SwitchParameter
- Use case-sensitive matching.
- -IncludeNested SwitchParameter
- Include nested tables inside table cells.
- -Path String
- Path to the document to open read-only for searching.
- -Text String
- Literal text to find in table cells.
- -Pattern String
- Regular expression pattern to find in table cells.
- -Document WordDocument
- Open document to inspect. The caller controls the document lifetime.
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.