How to Diagnose and Repair a Corrupted XLSX File

November 08, 2026 · XLSX.now Editorial · XLSX Essentials

Separate storage failure, structural damage and unsupported XLSX features before attempting repair.

Diagnosis: Identify the Failure Mode

Classify the corruption before selecting a repair method. An XLSX file is a ZIP archive containing XML components. A repair action suited to storage failure will destroy a file with structural damage.

Step 1: Test ZIP Container Integrity

unzip -t suspect.xlsx
  • "No errors detected": The container is intact. Corruption resides in XML content or the file uses features unsupported by the target application.
  • "bad CRC" or "unsupported compression method": Storage failure. Proceed to Repair: Storage Failure.
  • Command cannot open the file: The ZIP header is destroyed. Binary carving tools such as photorec may recover fragments, but the file structure is unrecoverable.

Step 2: Validate XML Content

If the ZIP test passes, check for malformed XML:

unzip suspect.xlsx -d temp_xlsx/
cd temp_xlsx
find . -name "*.xml" -exec xmllint --noout {} \; 2>&1 | grep -v "validates"
  • Errors reported: Structural damage. Proceed to Repair: Structural Damage.
  • No errors: The file is structurally valid. The failure is likely an unsupported feature.

Step 3: Identify Unsupported Features

A structurally sound XLSX can fail to open in an older or different application. Common causes:

  • Password-based encryption (OLE2 containers or encryptionInfo XML)
  • Custom XML extensions with vendor-specific tags
  • External chart data references to missing sources
  • Shared string table exceeding 64k unique strings in single-byte encoding contexts

Search the extracted contents:

grep -r "encryptionInfo\|oleObject" temp_xlsx/

If found, the file is not corrupt—it is incompatible with the target tool. Do not attempt repair.


Repair: Storage Failure

When unzip -t reports errors, the file has physical damage. Do not attempt in-place repair.

Extract Surviving Data

unzip -o suspect.xlsx -d temp_recovery/ 2>zip_errors.log

All files passing CRC checks are extracted. Entries listed in zip_errors.log are corrupt or missing. A bad CRC means the data is lost; do not attempt to fix the CRC value.

Rebuild a Minimal Workbook

  1. Create an empty XLSX using a reference implementation.
  2. Copy these files from temp_recovery/ if intact:
    • [Content_Types].xml
    • _rels/.rels
    • xl/workbook.xml
    • xl/_rels/workbook.xml.rels
    • Any intact xl/worksheets/sheetN.xml
  3. If xl/sharedStrings.xml is intact, copy it. If corrupt, substitute an empty shared strings table:
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="0" uniqueCount="0"/>

Hard limit: If xl/workbook.xml or [Content_Types].xml are missing, the structural skeleton is unrecoverable. Stop repair.

Expected outcome: Data from damaged ZIP entries is permanently lost. The rebuilt file contains only data from successfully extracted XML files.


Repair: Structural Damage

When the ZIP container is intact but XML is invalid, target specific XML failures.

Common XML Failures

  • Mismatched tags (<row> without </row>)
  • Invalid characters (non-UTF-8 bytes in string values)
  • Attribute values exceeding parser limits (Excel permits 32,767 characters per cell)
  • Missing namespace declarations

Automated Recovery

For a single file with a known error pattern:

xmllint --recover --noout xl/worksheets/sheet1.xml > sheet1_fixed.xml 2>recovery.log

The --recover flag closes unclosed tags and drops invalid characters. This operation is lossy and may discard entire rows.

Manual Repair of Shared String Table

xl/sharedStrings.xml is the most common failure point. If the workbook opens partially, the file likely has:

  • A missing count attribute on <sst>
  • A truncated final <si> element

Open the file in an editor that handles large files. Navigate to the last <si> element and verify it has a closing </si>. If the file ends abruptly, append </si></sst>.

Unrecoverable limit: If the shared string table root element is unparseable or the file is entirely missing, the workbook may open with all cell values blank. Text content cannot be recovered.


Unsupported Features: False Positives

A file passing all structural checks that still fails to open likely uses features outside the target application's scope.

Known Incompatibilities

Feature Symptom Fallback
Encryption (OLE2 or ECMA-376) "File is corrupt" or password prompt Decrypt in the original application, re-save unencrypted
External links (xl/externalLinks/) "References to external data" warning Remove links in a full Excel application
VBA macros (xl/macros/) "Unsupported macro" error Save as .xlsm or remove vbaProject.bin
Custom XML schemas Parser rejects unknown elements Strip custom namespaces with xmllint

Verify Feature Set

unzip -l suspect.xlsx | grep -E "\.(bin|vba|exe|encryption|ole)"

Any matches indicate features outside the standard XLSX specification. The Microsoft Open XML specification does not define handling for these extensions in a generic reader. Convert to a clean XLSX using the original application.


Validation After Repair

Run a three-stage check on any repaired file:

  1. ZIP integrity: unzip -t repaired.xlsx must return "No errors detected."
  2. XML validity: xmllint --noout on every XML file must report no errors.
  3. Semantic check: Open in a known-good reader (e.g., LibreOffice Calc). Verify cell count, sheet count, and key values. No error dialogs should appear.

Failure at stage 3 indicates data loss during repair exceeded recoverable thresholds.


Unrecoverable Conditions

Stop repair under these conditions:

  • No ZIP header: First two bytes are not PK. Binary carving may recover fragments; file structure is gone.
  • Zero-length critical files: xl/workbook.xml or [Content_Types].xml exist but are empty. No skeleton exists to rebuild.
  • Encryption without the key: No known method recovers content without the original password.
  • All XML validates but the application rejects the file: The file uses a proprietary extension not covered by the standard. The format is technically valid but not interoperable.

The only reliable recovery path for these cases is the original application that created the file.


Reference for repair corrupted xlsx file diagnostic checklist

Microsoft Open XML specification — structure of the ZIP container, XML schema, and mandatory files. Primary Reference