Validate and Repair Excel Workbooks
Edit on GitHubPreflight 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 Stopsurfaces runtime import warnings as errors.Test-OfficeDocument -Path .\Report.xlsxchecks 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 Accessibilitychecks accessible-delivery concerns.Get-OfficeDocumentInfo -Path .\Report.xlsx -Detailedreturns common counts and a native workbook snapshot inDetails.
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.