PHPExcel vs PHP_XLSXWriter Comparison


PHPExcel is a common library used for writing XLSX files. However when writing large spreadsheets, it starts to show its memory and CPU limitations.

PHPExcel discussions are full of reports of memory being exhausted.
* Out of memory when writing huge file
* Memory exhausted in large data
* Writing Large Dataset to Excel XLSX Failing
* How to handle large files

Below are a few test cases, writing large xlsx spreadsheet files with PHPExcel and PHP_XLSXWriter for comparison.

Case 1: 10 columns, 10,000 rows in 4 sheets (400,000 cells)
PHP_Excel: 458MB 101.55s
PHP_XLSXWriter: 11MB 7.56s
Case 2: 10 columns, 10,000 rows in 6 sheets (600,000 cells)
PHP_Excel: 685MB 202.72s
PHP_XLSXWriter: 15MB 11.31s
Case 3: 10 columns, 20,000 rows in 4 sheets (800,000 cells)
PHP_Excel: 912MB 301.31s
PHP_XLSXWriter: 22MB 14.94s


In a few simple tests, PHP_XLSXWriter shows a 98% savings on memory and 95% savings on time when compared to PHPExcel for writing large files. Though PHPExcel may have more features, it doesn't compare with PHP_XLSXWriter when it comes to performance.

Internally, PHPExcel stores a representation of each cell in memory before being able to write it. PHP_XLSXWriter on the other hand, writes the spreadsheet to a temporary file as it goes, which saves on memory and speed in cases of large files.

code snippets are licensed under Creative Commons CC-By-SA 3.0 (unless otherwise specified)