Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Set-OfficeWordTableCell

Aliases: WordTableCellStyle
Module PSWriteOffice
Aliases
WordTableCellStyle
Inputs
OfficeIMO.Word.WordTableCell
Outputs
OfficeIMO.Word.WordTableCell

Updates OfficeIMO Word table-cell content, layout, and merge settings.

Syntax

Set-OfficeWordTableCell [-Cell] <WordTableCell> [-CopyParagraphs] [-FitText <Boolean>] [-MarginBottomCentimeters <Double>] [-MarginLeftCentimeters <Double>] [-MarginRightCentimeters <Double>] [-MarginTopCentimeters <Double>] [-MergeDown <Int32>] [-MergeRight <Int32>] [-PassThru] [-ShadingFillColor <String>] [-ShadingPattern <WordShadingPattern>] [-SplitHorizontal <Int32>] [-SplitVertical <Int32>] [-Text <String>] [-TextDirection <WordTextDirection>] [-Width <Int32>] [-WidthType <Nil|Pct|Dxa|Auto>] [-WrapText <Boolean>] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Examples

Authored help example

Replace text in a cell after finding a table.

$doc = Get-OfficeWord -Path .\Handover.docx
$table = Find-OfficeWordTable -Document $doc -Text 'Risk marker' | Select-Object -First 1
$table |
    Get-OfficeWordTableCell -Row 2 -Column 2 |
    Set-OfficeWordTableCell -Text 'Investigating' -ShadingFillColor '#fff2cc' -ShadingPattern Clear
$doc | Close-OfficeWord -Save

Finds an existing table by text, replaces a target cell value, applies shading, and saves the document.

Highlight a status column in the first report table.

$doc = Get-OfficeWord -Path .\Report.docx
$table = $doc | Get-OfficeWordTable | Select-Object -First 1
$table |
    Get-OfficeWordTableCell -Column 2 |
    Set-OfficeWordTableCell -ShadingFillColor '#fff1f0' -ShadingPattern Clear -Width 2400 -WidthType Dxa
$doc | Save-OfficeWord -Path .\Report-StatusCells.docx

Reads cells from an OfficeIMO table object, applies cell shading and width, and saves the updated document.

Add readable padding to every cell in a report table.

$table | Get-OfficeWordTableCell | Set-OfficeWordTableCell -MarginTopCentimeters 0.12 -MarginBottomCentimeters 0.12 -MarginLeftCentimeters 0.16 -MarginRightCentimeters 0.16

Sets independent cell margins in centimeters. Omitted margins retain their values; pass null to remove an explicit margin.

Merge a heading row across columns.

$doc = Get-OfficeWord -Path .\Report.docx
$table = $doc | Get-OfficeWordTable | Select-Object -First 1
$table |
    Get-OfficeWordTableCell -Row 0 -Column 0 |
    Set-OfficeWordTableCell -MergeRight 2 -CopyParagraphs
$doc | Save-OfficeWord -Path .\Report-MergedHeader.docx

Uses the OfficeIMO merge operation exposed by the thin table-cell wrapper.

Parameters

-Cell WordTableCell requiredposition: 0pipeline: True (ByValue)
Table cell to update.
-CopyParagraphs SwitchParameter optional
Copy paragraphs while merging cells.
-FitText Boolean optional
Whether text should fit within the cell.
-MarginBottomCentimeters Double optional
Bottom cell padding in centimeters. Pass null to remove the explicit margin.
-MarginLeftCentimeters Double optional
Left cell padding in centimeters. Pass null to remove the explicit margin.
-MarginRightCentimeters Double optional
Right cell padding in centimeters. Pass null to remove the explicit margin.
-MarginTopCentimeters Double optional
Top cell padding in centimeters. Pass null to remove the explicit margin.
-MergeDown Int32 optional
Number of cells to merge downward.
-MergeRight Int32 optional
Number of cells to merge to the right.
-PassThru SwitchParameter optional
Emit the updated table cell.
-ShadingFillColor String optional
Cell shading fill color. Named colors and hexadecimal values are accepted.
-ShadingPattern WordShadingPattern optional
Cell shading pattern.
Possible values: Nil, Clear, Solid, HorizontalStripe, VerticalStripe, ReverseDiagonalStripe, DiagonalStripe, HorizontalCross, DiagonalCross, ThinHorizontalStripe, ThinVerticalStripe, ThinReverseDiagonalStripe, ThinDiagonalStripe, ThinHorizontalCross, ThinDiagonalCross, Percent5, Percent10, Percent12, Percent15, Percent20, Percent25, Percent30, Percent35, Percent37, Percent40, Percent45, Percent50, Percent55, Percent60, Percent62, Percent65, Percent70, Percent75, Percent80, Percent85, Percent87, Percent90, Percent95
-SplitHorizontal Int32 optional
Number of columns to split the cell into.
-SplitVertical Int32 optional
Number of rows to split the cell into.
-Text String optional
Replace the visible cell text.
-TextDirection WordTextDirection optional
Cell text direction.
Possible values: LeftToRightTopToBottom, LeftToRightTopToBottom2010, TopToBottomRightToLeft, TopToBottomRightToLeft2010, BottomToTopLeftToRight, BottomToTopLeftToRight2010, LeftToRightTopToBottomRotated, LeftToRightTopToBottomRotated2010, TopToBottomRightToLeftRotated, TopToBottomRightToLeftRotated2010, TopToBottomLeftToRightRotated, TopToBottomLeftToRightRotated2010
-Width Int32 optional
Cell width value.
-WidthType WordTableWidthUnit optional
Cell width unit type.
Possible values: Nil, Pct, Dxa, Auto
-WrapText Boolean optional
Whether text wraps in the cell.

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.