Excessive file size after writing from a template

Topics: User Forum
Nov 5, 2012 at 5:02 PM

PHPExcel version - 1.7.8

linux - Linux version 2.6.18-274.12.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-51))

PHP Version - 5.3.17

I have a sales reporting template that I use to create a weekly report.  Everything works perfectly, except for the output file size.

The input template is only 249kb in size, and yet the output file ends up being over 4mb in size.

There are a total of 97 cells that have any data put into them.  When I insert the data manually, the size stays correct.

Original Template size - 254,464

Manual Entry Output size - 254,464

PHPExcel Output size - 4,230,656

I based my code off of the 30template.php example.

Any thoughts on what could be causing this is appreciated!

If any other information is needed I'll respond with what I can.

Nov 6, 2012 at 8:00 PM
Edited Nov 6, 2012 at 8:02 PM

If the worksheet contains the data that you expect, then you really shouldn't worry about this. 4MB isn't particularly large for a file.

PHPExcel is not a file editor: it doesn't simply add a few extra cells into the original file that might simply add a few bytes to the resultant size. It loads the file, converting its content to a PHPExcel object; you modify that PHPExcel object; and when you save, it writes a new file from the content of that PHPExcel object. Excel itself has a lot of different options for the way it stores the spreadsheet data, and the resources to optimise to store them extremely efficiently when it saves. PHPExcel stores in a generic manner, without the overhead of determining how best to optimise the resultant file to a minimal size. PHPExcel may, for example, save additional default styles that aren't used in the workbook, whereas Excel itself may discard these. You don't mention which format you're using: .xlsx or .xls... the former is zip compressed; but the zip compression method used by ZipArchive may not match the compression method used by Excel.

So there's a whole host of factors that come into play that affect the size of a saved file: what's generally more important is that the content is correct.

Nov 7, 2012 at 3:39 PM
Edited Nov 7, 2012 at 3:40 PM

Thanks for the help!!

When I switch the template file over to the 2007 format and save the file to .xlsx format it comes out at only 224kb in size.  So it looks like telling Starbucks corporate that they need to upgrade their version of Office will be the fix I need, heh.

Thanks again,

~ Mike