Cmdlet
Clear-OfficeExcelRange
Clears values, formulas, styles and range metadata from a range, a header column or whole sheets.
Syntax
Clear-OfficeExcelRange
[-Document <ExcelDocument>]
[-Include <ExcelClearOptions[]>]
[-PassThru]
[[-Range] <String>]
[-Sheet <OfficeSheetSelector[]>]
[<CommonParameters>]#Parameter set:
RangeClear-OfficeExcelRange
[-Document <ExcelDocument>]
-Header <String>
[-HeaderRow <Int32>]
[-Include <ExcelClearOptions[]>]
[-IncludeHeader]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
[-Table <String>]
[<CommonParameters>]#Parameter set:
HeaderDescription
Native table schemas and their header labels remain in place while the selected data and metadata categories are cleared.
Examples
Clear the values of a range
Open-OfficeExcel -Path .\Templates\Weekly-Report.xlsx {
ExcelSheet 'Data' {
Clear-OfficeExcelRange A2:F200 -Include Values
}
}Removes the values from A2:F200 and keeps formatting, validation and comments.
Clear worksheet data and rules
Open-OfficeExcel -Path .\Reports\Weekly-Ops.xlsx {
ExcelSheet 'Data' {
$cleared = Clear-OfficeExcelRange -PassThru
Write-Verbose "Selected $cleared cells"
}
}Clears the supported data and rule categories on Data, retains table headers and reports the selected cell count.
Parameters
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -Include ExcelClearOptions[]
- Cell data and metadata categories to clear. Omission clears all supported categories.
- Possible values:
Values,Formulas,Styles,Comments,Hyperlinks,DataValidations,ConditionalFormatting,Merges,Sparklines,All - -PassThru SwitchParameter
- Emits the native result after the operation.
- -Range String
- A1 cell range on the selected worksheet.
- -Sheet OfficeSheetSelector[]
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -Header String
- Header text identifying the target column.
- -HeaderRow Int32
- One-based row containing the column headers.
- -IncludeHeader SwitchParameter
- Includes the header cell in the resolved column range.
- -Table String
- Native Excel table used to resolve the source range or header.
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.