Manatee

Excel says the file format or extension is not valid

Excel refuses to open a spreadsheet: 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.

That message covers two quite different situations, and it names both of them. Either the file is damaged, or its extension is lying about what it contains. The second is far more common, and it is quick to check.

Find out what the file actually is

macOS can identify a file by looking at its contents rather than its name:

file -b spreadsheet.xlsx

The answers you might get, and what each means:

  • Microsoft Excel 2007+ means a genuine XLSX. The extension is right, so the problem is elsewhere.
  • Zip archive data also means a genuine XLSX, because that is what an XLSX is underneath. Also fine.
  • Composite Document File V2 Document means an old-format XLS that has been given an .xlsx extension. Rename it to .xls.
  • CSV text or ASCII text means a CSV or tab-separated file named as a spreadsheet. Rename it to .csv.
  • HTML document text means a web page. Some systems export “Excel” files that are actually HTML tables. Rename it to .html and open it in a browser, or in Excel via File then Open, which will parse the table.
  • XML 1.0 document means an XML spreadsheet, an older interchange format. Rename to .xml.
  • data or empty means the file is damaged or was never written properly.

This one command resolves the majority of cases. A file exported by a reporting system, a bank, or a web application is very often not the format its extension claims.

If it is genuinely an XLSX

An XLSX is a ZIP archive containing XML files. That gives a precise integrity test, because a broken archive is a broken spreadsheet:

unzip -t spreadsheet.xlsx

No errors detected in compressed data means the container is intact and the problem is in the content or in Excel itself. Errors mean the file is damaged, and the amount of damage determines what can be recovered.

You can also look inside, which tells you whether the parts Excel needs are present:

unzip -l spreadsheet.xlsx | head -20

A healthy workbook lists [Content_Types].xml, a xl/workbook.xml, and one xl/worksheets/sheet1.xml per sheet. If the worksheet files are listed with sensible sizes, your data exists even if Excel will not open the file, which is a much better position than it appears.

The quarantine flag

A file downloaded from the internet or received through a messaging app carries a quarantine attribute, and Office applications sometimes refuse rather than explaining why.

xattr -l spreadsheet.xlsx

If com.apple.quarantine appears, clear it on a copy:

cp spreadsheet.xlsx clean.xlsx
xattr -c clean.xlsx

Only do this for a file you trust. The flag exists to make you think twice about content from elsewhere, and clearing it removes that check.

Related: files opened from a Downloads folder or straight from a mail attachment sometimes open in Protected View and behave strangely. Move the file to your Documents folder and open it from there.

When the file is genuinely damaged

If unzip -t reports errors, the archive is broken. How much you can retrieve depends on where the damage sits.

Excel has its own recovery path worth trying first: File, then Open, then select the file and use the arrow beside the Open button to choose Open and Repair. It succeeds more often than people expect, particularly for files damaged near the end.

If that fails, the ZIP structure gives another route, because the individual worksheet XML files may be intact even when the archive index is not:

mkdir extracted && cd extracted
unzip -o ../spreadsheet.xlsx 2>/dev/null
ls xl/worksheets/

unzip recovers what it can and reports what it cannot. Surviving sheetN.xml files contain your cell data as XML. It is not pleasant to read, and it is your data, which matters when the alternative is nothing.

Manatee automates this for Office documents: it reads the surviving parts of a damaged XLSX, DOCX or PPTX and writes a clean file containing what it could recover, working from a duplicate so the damaged original is never modified. It reports what came back rather than producing a file that Excel will also refuse. What you can recover from a corrupted Excel file goes through the realistic outcomes in more detail.

The macro format

One more variant that produces this message. A workbook containing macros must be saved as .xlsm, not .xlsx. A file renamed from one to the other is rejected. file -b will not distinguish them, but if you know the workbook contains macros, try renaming it to .xlsm.

A working order

  1. file -b thefile.xlsx to learn what it really is. Rename if the answer disagrees with the extension.
  2. xattr -l for a quarantine flag; clear it on a copy if the source is trusted.
  3. unzip -t to test the archive.
  4. Excel’s Open and Repair.
  5. Extract the worksheet XML with unzip -o and recover the data directly.

Questions

The file opens on Windows but not on my Mac. Usually the quarantine flag, or a difference in how strictly the two versions validate. Check xattr -l first, since that is Mac-specific and the likeliest explanation.

Why would a system export a file with the wrong extension? Because generating an HTML table or a CSV and naming it .xls was a widespread shortcut for years, and it works in older Excel versions, which parse whatever they are given. Newer versions validate properly and refuse.

Can I just rename the file and be done? If file -b identifies a real format that Excel supports, yes. Renaming does not alter content; it only changes which application claims it and how Excel interprets it.

The file is 0 bytes. Nothing was written. There is no recovery from an empty file. Look for an autosave copy, or in the Versions history if the file lived in iCloud or on an APFS volume.