Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Update-OfficeExcelText

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument System.String[]

Replaces text in cell values across a workbook, sheet or range.

Syntax

Update-OfficeExcelText
[-CaseSensitive]
[-Document <ExcelDocument>]
[-PassThru]
[-Pattern] <String>
[-Range <String>]
[-Replacement] <String>
[-Sheet <OfficeSheetSelector[]>]
[-Show]
[-SimpleMatch]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
#
Parameter set: Document
Update-OfficeExcelText
[-CaseSensitive]
[-PassThru]
[-Path] <String[]>
[-Pattern] <String>
[-Range <String>]
[-Replacement] <String>
[-Sheet <OfficeSheetSelector[]>]
[-Show]
[-SimpleMatch]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
#
Parameter set: Path
Update-OfficeExcelText
[-CaseSensitive]
-LiteralPath <String[]>
[-PassThru]
[-Pattern] <String>
[-Range <String>]
[-Replacement] <String>
[-Sheet <OfficeSheetSelector[]>]
[-Show]
[-SimpleMatch]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
#
Parameter set: LiteralPath

Examples

Replace text across a workbook

Update-OfficeExcelText -Path .\Templates\Price-List.xlsx -Pattern 'Fabrikam Ltd' -Replacement 'Northwind Traders' -SimpleMatch

Replaces the old company name in every cell of the workbook and saves it.

Rename hosts after a migration

$changed = Update-OfficeExcelText -Path .\Reports\Inventory.xlsx -Sheet Servers, Services -Pattern '^SRV-(\d+)$' -Replacement 'NW-APP-$1' -PassThru
"Renamed $changed cells"

Uses a regular expression to rename the old SRV hosts to the new naming scheme on the inventory sheets and reports how many cells changed.

Replace placeholders inside a block

Open-OfficeExcel -Path .\Templates\Quote.xlsx {
    Update-OfficeExcelText -Pattern '{{Customer}}' -Replacement 'Northwind Traders' -SimpleMatch
    Update-OfficeExcelText -Pattern '{{Date}}' -Replacement (Get-Date -Format 'yyyy-MM-dd') -SimpleMatch
}

Fills a template and replaces its placeholder text in the same Open-OfficeExcel block.

Parameters

-CaseSensitive SwitchParameter optional
Matches names and text using ordinal case sensitivity. Omission ignores case.
-Document ExcelDocument optionalpipeline: True (ByValue)sets: Document
Caller-owned workbook; omission uses the enclosing Excel content block.
-PassThru SwitchParameter optional
Emits the native result after the operation.
-Pattern String requiredposition: 1
Date or DateTime number format pattern.
-Range String optional
A1 cell range on the selected worksheet.
-Replacement String requiredposition: 2
Replacement text or regular-expression replacement pattern.
-Sheet OfficeSheetSelector[] optionalaliases: WorksheetName
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-Show SwitchParameter optional
Open the saved file in its registered application after a local block completes.
-SimpleMatch SwitchParameter optional
Uses literal text matching instead of regular expressions.
-WhatIf SwitchParameter optional
Shows what would happen if the command runs.
-Confirm SwitchParameter optional
Prompts for confirmation before running the command.
-Path String[] requiredposition: 0pipeline: True (ByValue)aliases: FilePathsets: Path
Workbook paths resolved with filesystem wildcard support.
-LiteralPath String[] requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath
Literal workbook paths, including FileInfo.FullName and provider PSPath.

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.