Why when open xls file generated by PHPExcel then click save the size decreases?

334 views Asked by At

I use PHPexcel_1.8 to generate Microsoft Excel 97-2003 Worksheet (.xls)

 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter->save($myFile);

If I open the file and press ctr+s (without making any change), the size drops almost to 50%.

1

There are 1 answers

6
Mark Baker On BEST ANSWER

Simple.... PHPExcel doesn't waste precious PHP overhead resources in speed and memory usage to optimize storage of the file data; whereas MS Excel will reduce filesize requirements by optimizing storage. Building a native Excel format file in PHP is slow and memory hungry already

As an example of this, all string data is maintained in a shared strings table. When two or more cells contain the same string value, MS Excel will point them both to the same entry in the shared strings table, so that the string data is only stored once. PHPExcel doesn't do this check to see if a string value is already in the shared strings table, but simply creates a new entry, so the string is stored twice. This reduces time taken to save the data by eliminating the overhead of checking is the string already in the table, but at a cost in duplication and hence in filesize.

The key question is "which is more important? To be able to read/edit/write native Excel files in PHP? To keep PHPExcel as fast and low-memory as possible? Or to have the smallest possible filesize on disk?"