Home » excel » Reading very large (more than 100MB) Excel files in PHP

Reading very large (more than 100MB) Excel files in PHP

Posted by: admin March 9, 2020 Leave a comment

Questions:

I’m trying to read a larger than 100MB Excel file using PHPExcel but it crashes while loading the file. I don’t need any styling. I tried using:

$objReader->setReadDataOnly(true);

but it still crashes.

Is there any efficient way to read this size of Excel file in PHP?

How to&Answers:

Try Spout: https://github.com/box/spout.

This is a PHP library that was created to solve your problem (reading/writing large files). Here is why it works:

Other libraries keep a representation of the spreadsheet in memory which make them subject to out of memory errors. Using some caching strategies will help with these kind of errors but will affect performance pretty badly.

On the other hand, Spout uses streams to read or write data. This means that there is only one row kept in memory at all times, all read/written rows being freed from memory. This allows fast read/write of dataset of any size! Give it a try 🙂