Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Clear-OfficeExcelRange

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument

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: Range
Clear-OfficeExcelRange
[-Document <ExcelDocument>]
-Header <String>
[-HeaderRow <Int32>]
[-Include <ExcelClearOptions[]>]
[-IncludeHeader]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
[-Table <String>]
[<CommonParameters>]
#
Parameter set: Header

Description

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 optionalpipeline: True (ByValue)
Caller-owned workbook; omission uses the enclosing Excel content block.
-Include ExcelClearOptions[] optional
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 optional
Emits the native result after the operation.
-Range String optionalposition: 0sets: Range
A1 cell range on the selected worksheet.
-Sheet OfficeSheetSelector[] optional
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-Header String requiredsets: Header
Header text identifying the target column.
-HeaderRow Int32 optionalsets: Header
One-based row containing the column headers.
-IncludeHeader SwitchParameter optionalsets: Header
Includes the header cell in the resolved column range.
-Table String optionalsets: Header
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.