Cmdlet
Update-OfficeExcelText
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:
DocumentUpdate-OfficeExcelText
[-CaseSensitive]
[-PassThru]
[-Path] <String[]>
[-Pattern] <String>
[-Range <String>]
[-Replacement] <String>
[-Sheet <OfficeSheetSelector[]>]
[-Show]
[-SimpleMatch]
[-WhatIf]
[-Confirm]
[<CommonParameters>]#Parameter set:
PathUpdate-OfficeExcelText
[-CaseSensitive]
-LiteralPath <String[]>
[-PassThru]
[-Pattern] <String>
[-Range <String>]
[-Replacement] <String>
[-Sheet <OfficeSheetSelector[]>]
[-Show]
[-SimpleMatch]
[-WhatIf]
[-Confirm]
[<CommonParameters>]#Parameter set:
LiteralPathExamples
Replace text across a workbook
Update-OfficeExcelText -Path .\Templates\Price-List.xlsx -Pattern 'Fabrikam Ltd' -Replacement 'Northwind Traders' -SimpleMatchReplaces 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
- Matches names and text using ordinal case sensitivity. Omission ignores case.
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -PassThru SwitchParameter
- Emits the native result after the operation.
- -Pattern String
- Date or DateTime number format pattern.
- -Range String
- A1 cell range on the selected worksheet.
- -Replacement String
- Replacement text or regular-expression replacement pattern.
- -Sheet OfficeSheetSelector[]
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -Show SwitchParameter
- Open the saved file in its registered application after a local block completes.
- -SimpleMatch SwitchParameter
- Uses literal text matching instead of regular expressions.
- -WhatIf SwitchParameter
- Shows what would happen if the command runs.
- -Confirm SwitchParameter
- Prompts for confirmation before running the command.
- -Path String[]
- Workbook paths resolved with filesystem wildcard support.
- -LiteralPath String[]
- 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.