Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/

Validate and Repair Excel Workbooks

Edit on GitHub

Preflight workbook operations, test integrity and accessibility, diagnose package state, and apply deliberate repairs.

Validation is a delivery stage, not an incidental side effect of opening a workbook. Keep inspection separate from repair so an automation run cannot silently rewrite a source file.

Preflight first

  • Import-OfficeExcel -Path .\Report.xlsx -Culture en-US -WarningAction Stop surfaces runtime import warnings as errors.
  • Test-OfficeDocument -Path .\Report.xlsx checks workbook integrity.
  • Add -Options (New-OfficeExcelTestOptions -Capability EditCellValues,ExportPdfReport -IncludeFeatures -IncludeRepairHints) to evaluate the intended operations and retain their repair hints.
  • Test-OfficeDocument -Path .\Report.xlsx -Check Accessibility checks accessible-delivery concerns.
  • Get-OfficeDocumentInfo -Path .\Report.xlsx -Detailed returns common counts and a native workbook snapshot in Details.

Validation returns IsValid, Diagnostics, and NativeReports. Inspect the native reports for workbook doctor and capability-preflight findings; use -Quiet only when the consumer needs a Boolean.

Repair explicitly

Use Repair-OfficeDocument only after inspecting the proposed repair class and preserving the original when required. Reopen the result, repeat the integrity checks, and compare it with the source if preservation matters.

For automated delivery, a useful gate is: create or update, save, preflight, test integrity, test accessibility when applicable, compare against a reference contract, then publish. The operational dashboard provides a substantial artifact for exercising that path.

Example source