Project

PSWriteOffice

PowerShell document automation across Word, Excel, PowerPoint, PDF, Reader, Confluence, Visio, and open text formats.

Stars 159
Forks 14
PowerShell Gallery downloads 158,661
Release v3.0.5
Language: C# Updated: 2026-09-03

API Reference

Cmdlet

Clear-OfficeExcelRange

Aliases: ExcelRangeClear
Namespace PSWriteOffice
Aliases
ExcelRangeClear
Inputs
OfficeIMO.Excel.ExcelDocument

Clears values, formulas, styles, and range metadata from an Excel worksheet range.

Remarks

Clears values, formulas, styles, and range metadata from an Excel worksheet range.

Examples

Authored help example

Clear cell contents without removing formatting.

PS>


Clear-OfficeExcelRange -Path .\Report.xlsx -Sheet Staging -Range B2:D20 -Contents -Hyperlinks -Confirm:$false
            Get-OfficeExcelRange -Path .\Report.xlsx -Sheet Staging -Range B2:D20 |
                Select-Object Address, Value, Formula
        

Removes values and formulas from the selected range and saves the workbook.

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.

Syntax

Clear-OfficeExcelRange [-All] [-Comments] [-ConditionalFormatting] [-Contents] [-DataValidations] [-Formulas] [-Hyperlinks] [-Merges] [-PassThru] -Range <String> [-Sheet <String>] [-SheetIndex <Int32>] [-Sparklines] [-Styles] [-Values] [<CommonParameters>]
#
Parameter set: Context

Parameters

All SwitchParameter optionalposition: namedpipeline: False
Clear all supported cell data and range metadata.
Comments SwitchParameter optionalposition: namedpipeline: False
Clear comments in the selected range.
ConditionalFormatting SwitchParameter optionalposition: namedpipeline: Falsealiases: ConditionalFormats
Clear conditional formatting rules that overlap the selected range.
Contents SwitchParameter optionalposition: namedpipeline: False
Clear values and formulas.
DataValidations SwitchParameter optionalposition: namedpipeline: Falsealiases: Validation, Validations
Clear data validation rules that overlap the selected range.
Formulas SwitchParameter optionalposition: namedpipeline: False
Clear formulas.
Hyperlinks SwitchParameter optionalposition: namedpipeline: False
Clear hyperlinks that overlap the selected range.
Merges SwitchParameter optionalposition: namedpipeline: False
Clear merged-cell definitions that overlap the selected range.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the object created or changed by the command.
Range String requiredposition: namedpipeline: False
A1 range to clear.
Sheet String optionalposition: namedpipeline: False
Worksheet name to update. Defaults to the current DSL sheet or the first workbook sheet.
SheetIndex Int32 optionalposition: namedpipeline: False
Worksheet index (0-based) to update. Defaults to the current DSL sheet or the first workbook sheet.
Sparklines SwitchParameter optionalposition: namedpipeline: False
Clear sparklines whose target cells overlap the selected range.
Styles SwitchParameter optionalposition: namedpipeline: Falsealiases: Formats
Clear cell style indexes.
Values SwitchParameter optionalposition: namedpipeline: False
Clear literal cell values.
Clear-OfficeExcelRange [-All] [-Comments] [-ConditionalFormatting] [-Contents] [-DataValidations] [-Formulas] [-Hyperlinks] [-Merges] [-PassThru] -Path <String> -Range <String> [-Sheet <String>] [-SheetIndex <Int32>] [-Sparklines] [-Styles] [-Values] [<CommonParameters>]
#
Parameter set: Path

Parameters

All SwitchParameter optionalposition: namedpipeline: False
Clear all supported cell data and range metadata.
Comments SwitchParameter optionalposition: namedpipeline: False
Clear comments in the selected range.
ConditionalFormatting SwitchParameter optionalposition: namedpipeline: Falsealiases: ConditionalFormats
Clear conditional formatting rules that overlap the selected range.
Contents SwitchParameter optionalposition: namedpipeline: False
Clear values and formulas.
DataValidations SwitchParameter optionalposition: namedpipeline: Falsealiases: Validation, Validations
Clear data validation rules that overlap the selected range.
Formulas SwitchParameter optionalposition: namedpipeline: False
Clear formulas.
Hyperlinks SwitchParameter optionalposition: namedpipeline: False
Clear hyperlinks that overlap the selected range.
Merges SwitchParameter optionalposition: namedpipeline: False
Clear merged-cell definitions that overlap the selected range.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the object created or changed by the command.
Path String requiredposition: 0pipeline: Falsealiases: FilePath, InputPath
Workbook path to update.
Range String requiredposition: namedpipeline: False
A1 range to clear.
Sheet String optionalposition: namedpipeline: False
Worksheet name to update. Defaults to the current DSL sheet or the first workbook sheet.
SheetIndex Int32 optionalposition: namedpipeline: False
Worksheet index (0-based) to update. Defaults to the current DSL sheet or the first workbook sheet.
Sparklines SwitchParameter optionalposition: namedpipeline: False
Clear sparklines whose target cells overlap the selected range.
Styles SwitchParameter optionalposition: namedpipeline: Falsealiases: Formats
Clear cell style indexes.
Values SwitchParameter optionalposition: namedpipeline: False
Clear literal cell values.
Clear-OfficeExcelRange [-All] [-Comments] [-ConditionalFormatting] [-Contents] [-DataValidations] -Document <ExcelDocument> [-Formulas] [-Hyperlinks] [-Merges] [-PassThru] -Range <String> [-Sheet <String>] [-SheetIndex <Int32>] [-Sparklines] [-Styles] [-Values] [<CommonParameters>]
#
Parameter set: Document

Parameters

All SwitchParameter optionalposition: namedpipeline: False
Clear all supported cell data and range metadata.
Comments SwitchParameter optionalposition: namedpipeline: False
Clear comments in the selected range.
ConditionalFormatting SwitchParameter optionalposition: namedpipeline: Falsealiases: ConditionalFormats
Clear conditional formatting rules that overlap the selected range.
Contents SwitchParameter optionalposition: namedpipeline: False
Clear values and formulas.
DataValidations SwitchParameter optionalposition: namedpipeline: Falsealiases: Validation, Validations
Clear data validation rules that overlap the selected range.
Document ExcelDocument requiredposition: namedpipeline: True (ByValue)
Workbook to update outside the DSL context.
Formulas SwitchParameter optionalposition: namedpipeline: False
Clear formulas.
Hyperlinks SwitchParameter optionalposition: namedpipeline: False
Clear hyperlinks that overlap the selected range.
Merges SwitchParameter optionalposition: namedpipeline: False
Clear merged-cell definitions that overlap the selected range.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the object created or changed by the command.
Range String requiredposition: namedpipeline: False
A1 range to clear.
Sheet String optionalposition: namedpipeline: False
Worksheet name to update. Defaults to the current DSL sheet or the first workbook sheet.
SheetIndex Int32 optionalposition: namedpipeline: False
Worksheet index (0-based) to update. Defaults to the current DSL sheet or the first workbook sheet.
Sparklines SwitchParameter optionalposition: namedpipeline: False
Clear sparklines whose target cells overlap the selected range.
Styles SwitchParameter optionalposition: namedpipeline: Falsealiases: Formats
Clear cell style indexes.
Values SwitchParameter optionalposition: namedpipeline: False
Clear literal cell values.