# Compare-OfficeExcelRange

Compares two Excel worksheets or ranges and returns cell-level differences.

Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

[View on GitHub](https://github.com/EvotecIT/OfficeIMO/tree/master/PowerShell/PSWriteOffice) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteOffice/releases/tag/v3.0.5) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteOffice/0.2.0)

Stars **727**

Forks **84**

Open issues **7**

Total downloads **5,275,783**

Release **OfficeIMO-v3.6.2**

Language: C# Updated: 2026-11-24

Cmdlet 

Aliases: Compare-OfficeExcelSheet, ExcelCompare

**Module**

`PSWriteOffice`

**Aliases**

`Compare-OfficeExcelSheet` `ExcelCompare`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Outputs**

`OfficeIMO.Excel.ExcelRangeDifference`

**Source**

[CompareOfficeExcelRangeCommand.cs:20](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/CompareOfficeExcelRangeCommand.cs#L20) 

Compares two Excel worksheets or ranges and returns cell-level differences.

## Syntax

```
Compare-OfficeExcelRange
[-IgnoreCase]
[-LeftRange <String>]
[-LeftSheet <String>]
[-LeftSheetIndex <Int32>]
[-Path] <String>
[-RightPath <String>]
[-RightRange <String>]
[-RightSheet <String>]
[-RightSheetIndex <Int32>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
```

[#](#method-compare-officeexcelrange-switchparameter-string-string-int32-string-string-string-string-int32-switchparameter-switchparameter)

Parameter set: `Path`

```
Compare-OfficeExcelRange
-Document <ExcelDocument>
[-IgnoreCase]
[-LeftRange <String>]
[-LeftSheet <String>]
[-LeftSheetIndex <Int32>]
[-RightDocument <ExcelDocument>]
[-RightRange <String>]
[-RightSheet <String>]
[-RightSheetIndex <Int32>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
```

[#](#method-compare-officeexcelrange-exceldocument-switchparameter-string-string-int32-exceldocument-string-string-int32-switchparameter-switchparameter)

Parameter set: `Document`

```
Compare-OfficeExcelRange
[-IgnoreCase]
[-LeftRange <String>]
[-LeftSheet <String>]
[-LeftSheetIndex <Int32>]
[-RightDocument <ExcelDocument>]
[-RightRange <String>]
[-RightSheet <String>]
[-RightSheetIndex <Int32>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
```

[#](#method-compare-officeexcelrange-switchparameter-string-string-int32-exceldocument-string-string-int32-switchparameter-switchparameter)

Parameter set: `Context`

## Examples

### Compare current and expected ranges before publishing.

```powershell
$differences = Compare-OfficeExcelRange -Path .\Report.xlsx -LeftSheet Current -RightSheet Expected -LeftRange A1:D20 -RightRange A1:D20 -TrimStrings -IgnoreCase
if ($differences) {
    $differences | Export-Csv -Path .\RangeDifferences.csv -NoTypeInformation
}
```

Compares two ranges and exports cell-level differences when the workbook does not match the expected sheet.

## Parameters

**-IgnoreCase SwitchParameter optional**

Compare strings case-insensitively.

**-LeftRange String optional**

Left A1 range. Defaults to the left worksheet used range.

**-LeftSheet String optional**

Left worksheet name. Defaults to the current sheet in a sheet block, otherwise the first sheet.

**-LeftSheetIndex Int32 optional**

Left worksheet index.

**-Path String requiredposition: 0aliases: FilePath, InputPath, LeftPathsets: Path**

Left workbook path.

**-RightPath String optionalsets: Path**

Optional right workbook path. Defaults to the left workbook.

**-RightRange String optional**

Right A1 range. Defaults to the right worksheet used range.

**-RightSheet String optional**

Right worksheet name. Defaults to the left sheet.

**-RightSheetIndex Int32 optional**

Right worksheet index.

**-StrictNullEmpty SwitchParameter optional**

Treat null and empty string values as different.

**-TrimStrings SwitchParameter optional**

Compare strings after trimming whitespace.

**-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document**

Left workbook object.

**-RightDocument ExcelDocument optionalsets: Document, Context**

Optional right workbook object. Defaults to the left 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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

Evotec API Reference Copyright 2026 Evotec Services

<!-- PowerForge markdown artifact sha256:70B535A717817E18F9AF9863B586523194C2EED0F5ECB16687F0084D187457BA -->
