Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Compare-OfficeExcelRange

Aliases: Compare-OfficeExcelSheet, ExcelCompare
Module PSWriteOffice
Aliases
Compare-OfficeExcelSheet ExcelCompare
Inputs
OfficeIMO.Excel.ExcelDocument
Outputs
OfficeIMO.Excel.ExcelRangeDifference

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>]
#
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>]
#
Parameter set: Document
Compare-OfficeExcelRange [-IgnoreCase] [-LeftRange <String>] [-LeftSheet <String>] [-LeftSheetIndex <Int32>] [-RightDocument <ExcelDocument>] [-RightRange <String>] [-RightSheet <String>] [-RightSheetIndex <Int32>] [-StrictNullEmpty] [-TrimStrings] [<CommonParameters>]
#
Parameter set: Context

Examples

Authored help example

Compare current and expected ranges before publishing.

$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.