Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Compare-OfficeExcelRange

Module
PSWriteOffice
Inputs
OfficeIMO.Excel.ExcelDocument

Compares two worksheets or ranges cell by cell.

Syntax

Compare-OfficeExcelRange
[[-DifferencePath] <String>]
[-DifferenceRange <String>]
[-DifferenceSheet <OfficeSheetSelector>]
[-IgnoreCase]
[-Range <String>]
[-ReferencePath] <String>
[-Sheet <OfficeSheetSelector>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
#
Parameter set: Path
Compare-OfficeExcelRange
[-DifferenceDocument <ExcelDocument>]
[-DifferenceRange <String>]
[-DifferenceSheet <OfficeSheetSelector>]
[-IgnoreCase]
[-Range <String>]
-ReferenceDocument <ExcelDocument>
[-Sheet <OfficeSheetSelector>]
[-StrictNullEmpty]
[-TrimStrings]
[<CommonParameters>]
#
Parameter set: Document

Examples

Compare a sheet in two versions

Compare-OfficeExcelRange -ReferencePath .\Finance\Budget-v1.xlsx -DifferencePath .\Finance\Budget-v2.xlsx -Sheet Budget |
                Select-Object Kind, ReferenceCell, ReferenceValue, DifferenceValue

Lists the cells of the Budget sheet that differ between two versions of the workbook.

Reconcile two lists in one workbook

$compare = @{
    ReferencePath   = '.\Finance\Reconciliation-October.xlsx'
    Sheet           = 'Ledger'
    Range           = 'A1:F400'
    DifferenceSheet = 'Bank'
    DifferenceRange = 'A1:F400'
}
Compare-OfficeExcelRange @compare -TrimStrings -IgnoreCase |
    Export-OfficeExcel -Path .\Finance\Reconciliation-Differences.xlsx -Title 'Ledger and bank differences'

Compares the ledger with the bank statement range by range, ignoring case and stray spaces, and writes the differences to a review workbook.

Parameters

-DifferencePath String optionalposition: 1sets: Path
Workbook path to compare against.
-DifferenceRange String optional
A1 range containing the comparison values in the difference workbook.
-DifferenceSheet OfficeSheetSelector optional
Worksheet selector in the difference workbook.
-IgnoreCase SwitchParameter optional
Compare strings case-insensitively.
-Range String optional
A1 cell range on the selected worksheet.
-ReferencePath String requiredposition: 0sets: Path
Path to the workbook containing the reference values.
-Sheet OfficeSheetSelector optional
Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
-StrictNullEmpty SwitchParameter optional
Treat null and empty string values as different.
-TrimStrings SwitchParameter optional
Compare strings after trimming whitespace.
-DifferenceDocument ExcelDocument optionalsets: Document
Workbook document to compare against.
-ReferenceDocument ExcelDocument requiredpipeline: True (ByValue)sets: Document
Caller-owned workbook containing the reference values.

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.