I’ve been using the PEAR library Spreadsheet_Excel_Writer for years. It’s a relatively easy way to generate .xls files in the native format, but it hasn’t been maintained for a while now. So I’ve got some older code running this library, and want to keep it running.
I just recently upgraded to a newer server, which involved moving from CentOS 5 to 7, and from PHP 5.4 to 5.6. I’m not sure which of those changes broke my old code, since they were simultaneous, but previously working downloads of spreadsheets now started to give an error reading:
We found a problem with come content in ‘filename.xls’. Do you want us to try to recover as much as we can? …
And, of course, clicking Yes doesn’t do anything useful to allow the file to be opened.
I didn’t want to have to rewrite the old code to use a newer library, like PHPExcel. This specific error message lead me to a solution that took someone else two days to figure out. This was a lifesaver.
This assumes that you have control over your server, as the change is made outside of the /home/account/ directory that you’re given under a CPanel server. If you don’t have control over your server, you’ll have to send your host to this page for instructions.
The fix is very simple. Change line 623 of
/usr/local/lib/php/OLE/PPS/Root.php
from
fwrite($FILE, pack(“V”, 1));
to
fwrite($FILE, pack(“V”, $num_sb_blocks));
and now your old Spreadsheet Excel Writer code can keep on working, without involving a rewrite of your code.