Corrupt xlsx

Topics: User Forum
Oct 2, 2011 at 8:50 PM
Edited Oct 3, 2011 at 1:53 AM

Working perfect for me for csv, but having problems with excel 2007.

Donated 50 euros - as it is working for me sort of but would like some help to eliminate the corruption.

Suspecting php_zip going by what I have read of others recieving the "corrupt file attempt repair" message when opening the file in excel. The file will open and repair incidentally! After saving in excel the binary files are different of course. After the test code I have included relevant phpinfo output below.

Renaming the saved file with a zip extension won't open, however letting excel repair the corrupt file then saving and renaming as zip will open of course.

ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'includes/PHPExcel');
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';

$objPHPExcel = new PHPExcel();

ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'includes/PHPExcel');
include 'PHPExcel.php';include 'PHPExcel/Writer/Excel2007.php';

// Create new PHPExcel object$objPHPExcel = new PHPExcel();
getProperties()->setCreator("Maarten Balliauw"); $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw"); $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!'); $objPHPExcel->getActiveSheet()->setTitle('Simple'); $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); ?>



Zip enabledExtension Version $Id: php_zip.c 308107 2011-02-07 16:20:16Z pajoye $Zip version 1.9.1Libzip version 0.9.0

XML Support activeXML Namespace Support activelibxml2 Version 2.6.32

Oct 2, 2011 at 8:57 PM
Edited Oct 5, 2011 at 6:24 AM

Forgot to state php 5.3.6 on LAMP.

Also have tested the file generated in my WAMP test environment and works perfectly - php 5.3.0.

There are differences in the good file from WAMP to bad file on LAMP when comparing with a hex editor - also LAMP file is 1 byte larger.

Have just tried upgrading php on lamp in order to get updated php_zip and still same problem even with updated php_zip now.

Is there a php setting that could be causing this? It is hard to belive that the zip utilitity would be buggy in two different versions on lamp.


Zip enabled
Extension Version $Id: php_zip.c 313665 2011-07-25 11:42:53Z felipe $
Zip version 1.9.1
Libzip version 0.9.0


Oct 5, 2011 at 6:24 AM


Is there anybody than can help with this? I don't mind making another small donation - donated 50 euros so far.

Kind regards


Oct 5, 2011 at 9:39 AM

try opening a working and corrupt file in a hex editor. I suspect that a BOM (Byte-order-mark) may be the cause of your problems. Check the first byte in the xlsx files.

Oct 5, 2011 at 8:31 PM

Hi Borft, thanks for the reponse - I will google BOM now!

Differences are

Offset Bad file (linux) Good file (windows)
0A 0B 82 5D 25 65
19003 19004            82 5D 25 65
2A005 2A006 82 5D 25 65
3c006 3c007 82 5D 25 65
5700d 5700e 82 5d 25 65
58001 - 13 e6 90 8e a3           df c6 e1 86 a2

and then heaps of differences, but the first few bytes are actually the same - write until byte ten. I notice that most these problems are with a bad php_zip in windows where  my windows one is fine but something going wrong on my linux. Could there be a php setting behind this? Its unlikely that 2 different copies of php_zip would be wrong for linux - coming compiled into the latest versions of php on debian.