# Clear-OfficeExcelRange

Clears values, formulas, styles and range metadata from a range, a header column or whole sheets.

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[ClearOfficeExcelRangeCommand.cs:35](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Excel/ClearOfficeExcelRangeCommand.cs#L35) 

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>]
```

[#](#method-clear-officeexcelrange-exceldocument-excelclearoptions-switchparameter-string-officesheetselector)

Parameter set: `Range`

```
Clear-OfficeExcelRange
[-Document <ExcelDocument>]
-Header <String>
[-HeaderRow <Int32>]
[-Include <ExcelClearOptions[]>]
[-IncludeHeader]
[-PassThru]
[-Sheet <OfficeSheetSelector[]>]
[-Table <String>]
[<CommonParameters>]
```

[#](#method-clear-officeexcelrange-exceldocument-string-int32-excelclearoptions-switchparameter-switchparameter-officesheetselector-string)

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

```powershell
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

```powershell
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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:511F54237DCBFF4B644B5B6DD6B7F0245B951F3218FF314F4E8D11341D0384DB -->
