Cookbook

Corrupted XLSX

Internally, a XLSX file is a ZIP with a set of files that makes the spreadsheet, including XML, images and other binaries. If when opening a XLSX file MS Excel shows an error alert regarding corrupted content, it may be due to two issues:

  • The XLSX file is not valid and it is not possible to open it. This is the most common issue about corrupted spreadsheet, and it means that the web server or PHP are adding extra content to the file at the beginning or the end, e.g when it is downloaded. It is possible to see those additional contents by opening the XLSX with a hex-editor. This way you can trace their origin and thus prevent them to be added.
  • The XLSX file shows an error alert and MS Excel usually lets you open it after repairing its content. The error is that some of the tags or attributes are wrong, for example, using a negative value for fields that only allow positive ones. In this case it is advisable to comment fragments of the code until you find the line that causes the error when opening it.