Fix Excel Error: The file format or file extension is not valid

beginnerπŸ“Š Microsoft Excel2026-03-23| Microsoft Excel 2016, 2019, 2021, Microsoft 365 β€” Windows 10/11, macOS

Error Message

The file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
#excel#file-format#corrupted#xlsx

TL;DR

Excel throws this error when the file extension doesn't match the actual format inside, or when the file is partially corrupted. Fastest fix: rename the extension to match the real format, or use File β†’ Open β†’ Open and Repair.

When This Happens

You double-click an .xlsx file β€” or .xls, .csv, .xlsm β€” and Excel immediately pops up:

The file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

Here's what usually causes it:

  • Someone saved the file as .xlsx but the contents are actually CSV or HTML
  • A download got cut off β€” you have a partial file sitting on disk
  • The file was manually renamed with the wrong extension (a .csv dressed up as .xlsx)
  • A third-party tool β€” an ERP, a reporting system β€” wrote a non-standard format and slapped an Excel extension on it
  • Antivirus or endpoint security software rewrote bytes in the file during a scan

Fix 1: Find Out What the File Actually Is

Don't guess. Check the real format first β€” it takes 10 seconds and tells you exactly which fix to use.

# Windows (PowerShell)
Format-Hex -Path "yourfile.xlsx" | Select-Object -First 2

# macOS / Linux
file yourfile.xlsx
xxd yourfile.xlsx | head -3

A real .xlsx file should show this:

yourfile.xlsx: Zip archive data   # xlsx is a ZIP internally

# Hex: PK\x03\x04  (50 4B 03 04)

See HTML document or ASCII text instead? The file was never Excel to begin with. It just has the wrong extension.

Rename to match the real format

# If `file` reports HTML:
cp yourfile.xlsx yourfile.html
# Open in a browser, copy the data, paste into a fresh Excel sheet

# If it's actually CSV:
cp yourfile.xlsx yourfile.csv
# Open with Excel normally

Fix 2: Open and Repair (Excel's Built-in Tool)

The extension is correct but the file still won't open? It's probably partially corrupted. Excel has a built-in repair tool β€” most people don't know where to find it.

  • Launch Excel first β€” do not double-click the file
  • Go to File β†’ Open β†’ Browse
  • Select the file, then click the dropdown arrow next to the Open button
  • Choose Open and Repair…
  • Try Repair first. If that fails, choose Extract Data

This works surprisingly well β€” as long as Excel can read the core ZIP structure, it recovers the data.

Fix 3: Unzip the .xlsx Manually

Here's something most users don't realize: an .xlsx file is just a ZIP archive with XML inside. You can crack it open directly:

# Rename and extract
cp yourfile.xlsx yourfile.zip
unzip yourfile.zip -d extracted_excel/
ls extracted_excel/

A healthy .xlsx looks like this inside:

extracted_excel/
β”œβ”€β”€ [Content_Types].xml
β”œβ”€β”€ _rels/
β”œβ”€β”€ xl/
β”‚   β”œβ”€β”€ workbook.xml
β”‚   β”œβ”€β”€ worksheets/
β”‚   └── sharedStrings.xml
└── docProps/

Missing xl/ or getting an "end-of-central-directory" error from unzip? The file is genuinely corrupted. Jump to Fix 4.

Fix 4: Extract Data with Python

When Excel gives up, Python often doesn't. Even partially corrupted files can be read programmatically β€” enough to salvage the data.

pip install openpyxl pandas
import pandas as pd

try:
    df = pd.read_excel("yourfile.xlsx", engine="openpyxl")
    print(f"Recovered {len(df)} rows")
    df.to_excel("yourfile_clean.xlsx", index=False)
except Exception as e:
    print(f"Failed: {e}")

    # File is actually CSV with wrong extension?
    df = pd.read_csv("yourfile.xlsx")
    df.to_excel("yourfile_clean.xlsx", index=False)

The output yourfile_clean.xlsx is a fresh, valid file β€” stripped of any structural damage from the original.

Fix 5: Restore a Previous Version

Got OneDrive, SharePoint, or Windows shadow copies? You may have a clean version sitting right there.

# Windows β€” check shadow copies
Right-click the file β†’ Properties β†’ Previous Versions tab

On OneDrive: open the file in the web interface β†’ click Version History in the top menu β†’ restore the version from before it broke. Versions go back 30 days on personal plans, 180 days on Microsoft 365 Business.

Fix 6: Re-download or Re-export

A cut-off download is the single most common cause of this error. Just grab the file again. While you're at it, compare the file size against what the server reports β€” a 45 KB file that should be 2.3 MB is a dead giveaway.

For files exported from internal systems: re-run the export job. ERP and reporting tools sometimes crash halfway through writing the file, leaving a valid-looking but broken stub on disk.

Verification

Once you've applied a fix, confirm everything is actually working:

  • Excel opens the file with no warning dialogs
  • All sheets, data, and formatting are present
  • Run file yourfile.xlsx β€” it should report Zip archive data
  • If you used Python, check row count: print(len(df)) should match what you expect from the source

Preventing This Going Forward

  • Generating Excel files in code? Use openpyxl or xlsxwriter β€” never rename a CSV to .xlsx and call it done
  • After any file transfer or download, spot-check the file size; add sha256sum verification to critical pipelines
  • For third-party exports, validate the output format automatically before it reaches end users β€” catch it in the pipeline, not in someone's inbox

Related Error Notes