Read Xlsx file in PhpSpreadsheet

Read Xlsx file in PhpSpreadsheet

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Read Xlsx file in PhpSpreadsheet

Attempting to load an .xlsx file created in Microsoft Excel often triggers a baffling exception when using PhpSpreadsheet: Unable to identify a reader for this file. This error typically surfaces inside IOFactory::load() or when manually instantiating a reader. If you bypass the factory and explicitly call $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); followed by $reader->load($file), the error shifts to a cascade of ZipArchive warnings indicating an "Invalid or uninitialized Zip object."

The root cause isn't usually a missing PHP extension or incorrect file permissions. Instead, it stems from how the library attempts to validate the file before opening it. The IOFactory::identify() method iterates through available readers and checks if they can handle the specific filename. It relies on each reader's canRead() method returning true to instantiate that reader.

In many cases involving .xlsx files, this validation fails prematurely. When ZipArchive::open() is invoked inside the Xlsx reader's canRead() logic, it returns an error code like ZipArchive::ER_NOENT, suggesting the file does not exist. However, the file clearly exists on the filesystem. This discrepancy usually points to a mismatch in how the underlying ZIP archive is being parsed or a corruption within the specific Excel file format being used.

While older libraries like PHPSpreadsheet (the predecessor) could sometimes be coerced into working by switching the internal ZIP handler from ZipArchive to PCLZip via settings, that approach is no longer viable for modern PhpSpreadsheet versions. The library architecture has evolved, and manual overrides of the ZIP class are deprecated or unsupported.

To resolve this in a production environment, you must first validate the integrity of the source file using standard Unix tools. Run the following command in your terminal:

file test.xlsx

If the output reads Microsoft Excel 2007+, the file is technically valid OOXML. If it reads Microsoft OOXML, it adheres strictly to the Open Office XML standard. Despite these distinctions, PhpSpreadsheet should handle both. If file confirms validity but the library still throws an exception, the issue is likely internal to how the reader detects the magic bytes or structure of that specific workbook.

Ensure you are not relying on legacy workarounds found in outdated forums. The solution does not involve modifying IOFactory.php manually or injecting different ZIP libraries into your vendor path. These modifications break dependency management and upgrade paths.

The most robust approach is to verify that the file was exported correctly. Sometimes, Excel exports files with hidden corruption that standard viewers miss but strict parsers like PhpSpreadsheet catch immediately. Try saving the spreadsheet in LibreOffice Calc and re-exporting it as .xlsx before attempting to load it again. If the error persists even after regeneration, check your Apache logs for specific stack traces that might reveal if a missing dependency is causing the ZipArchive initialization to fail silently.

If the file remains unreadable despite being valid OOXML, consider whether the file uses a structure unsupported by your current version of PhpSpreadsheet. Upgrading to the latest stable release often resolves compatibility issues with newer Excel features or file formats introduced in recent versions of Microsoft Office.

composer update phpoffice/phpspreadsheet

Always test reading a known-good sample file first. If that works, the problem is isolated to your specific source file. If it fails, the issue lies within the library configuration or version compatibility.

Our network