# Merge and Compare Excel Workbooks

Consolidate selected worksheets and produce explicit workbook or range differences for review and delivery gates.

Copy selected sheets into an existing target workbook, then compare the result with a baseline.

## Consolidate selected sheets

Start with an existing target workbook, or create one with `New-OfficeExcel`.

```powershell
Copy-OfficeExcelSheet -Path '.\Consolidated.xlsx' `
    -Source '.\Regions.xlsx' `
    -Sheet North,South `
    -NamePrefix 'Region '
```

Use a stable prefix when sources can contain the same sheet names. Copy mode and name-validation options let the operation match the preservation and naming policy.

## Compare a candidate

`Compare-OfficeDocument -ReferencePath .\Before.xlsx -DifferencePath .\After.xlsx` checks cells, styles, named ranges, tables, worksheet metadata, and comments. The common report exposes `AreEqual`, `Differences`, and `NativeReport`. Pass `New-OfficeExcelCompareOptions` through `-Options` to choose the comparison scope. Skip categories only when the delivery contract says they do not matter. `Compare-OfficeExcelRange` narrows the comparison to a known business area.

The [merge-workbooks recipe](https://github.com/EvotecIT/OfficeIMO/blob/3b680b1b6fb15a268ff5525a4ca6cdd70b2f6613/PowerShell/PSWriteOffice/Examples/Excel/Recipe-Excel-MergeWorkbooks.ps1) consolidates two regional sheets. The [compare-workbooks recipe](https://github.com/EvotecIT/OfficeIMO/blob/3b680b1b6fb15a268ff5525a4ca6cdd70b2f6613/PowerShell/PSWriteOffice/Examples/Excel/Recipe-Excel-CompareWorkbooks.ps1) creates a controlled cell difference and reports it.

After a merge, run the checks described in [validation and repair](/docs/pswriteoffice/excel-validation-repair/).

<!-- PowerForge markdown source sha256:964DB47595B39F77A27E82ACCCDF5DBDCF544F5C36C6BE15B06085265022663F; title=True -->

<!-- PowerForge markdown artifact sha256:541F38646FA42C570A4673DC51760ECBCD53C2106B52054037D958BF78C6B77F -->
