Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Find-OfficeWordTable

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

Finds Word tables containing matching cell text.

Syntax

Find-OfficeWordTable [-CaseSensitive] [-IncludeNested] [-Path] <String> [-Text] <String> [<CommonParameters>]
#
Parameter set: PathText
Find-OfficeWordTable [-CaseSensitive] [-IncludeNested] [-Path] <String> [-Pattern] <String> [<CommonParameters>]
#
Parameter set: PathRegex
Find-OfficeWordTable [-CaseSensitive] -Document <WordDocument> [-IncludeNested] [-Text] <String> [<CommonParameters>]
#
Parameter set: DocumentText
Find-OfficeWordTable [-CaseSensitive] -Document <WordDocument> [-IncludeNested] [-Pattern] <String> [<CommonParameters>]
#
Parameter set: DocumentRegex

Description

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

Authored help example

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 -Save

Shows the common existing-document workflow: locate the table, mutate it, then save the open document.

Parameters

-CaseSensitive SwitchParameter optional
Use case-sensitive matching.
-IncludeNested SwitchParameter optional
Include nested tables inside table cells.
-Path String requiredposition: 0aliases: FilePath, InputPathsets: PathText, PathRegex
Path to the document to open read-only for searching.
-Text String requiredposition: 1sets: PathText, DocumentText
Literal text to find in table cells.
-Pattern String requiredposition: 1sets: PathRegex, DocumentRegex
Regular expression pattern to find in table cells.
-Document WordDocument requiredpipeline: True (ByValue)sets: DocumentText, DocumentRegex
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.