Write corrupted files

Topics: Developer Forum
Sep 2, 2009 at 3:45 PM

Hello

I get a corrupted file when I simply open an xlsx file and save it :

 

set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');

// Class requirements
require_once('PHPExcel.php');
require_once('PHPExcel/Reader/Excel2007.php');
require_once('PHPExcel/Writer/Excel2007.php');

$file_name = 'test_xls.xlsx';

$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($file_name);
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel, "Excel2007");
$objWriter->save($file_name);

The second time I run the script, "$objPHPExcel = $objReader->load($file_name); " throw an error : 

Warning: ZipArchive::getFromName() [ziparchive.getfromname]: Invalid or unitialized Zip object in D:\_opensource\_silex\_repository_open_source\trunk\silex_server\cgi\scripts\Classes\PHPExcel\Reader\Excel2007.php on line 327

Warning: Invalid argument supplied for foreach() in D:\_opensource\_silex\_repository_open_source\trunk\silex_server\cgi\scripts\Classes\PHPExcel\Reader\Excel2007.php on line 328

-------------------------------------

NB : we (the silex team) are using phpExcel for a client again :-) I even made a first draft of a phpExcel component for Silex. It is available from Silex managers. Thank you for your work!

And do not hesitate to contact us ( http://silexlabs.com )

Developer
Sep 2, 2009 at 4:01 PM

I don't think we have seen this bug before. Is the xlsx file you are reading available somewhere so we can test? Or you can send me the xlsx file: erik at phpexcel dot net

Sep 2, 2009 at 5:32 PM
Edited Sep 2, 2009 at 5:35 PM

great thank you

here is the excel file before writing: http://hoyau.info/transfert/before-test_xls.xlsx

here is the excel file after writing (corrupted): http://hoyau.info/transfert/after-test_xls.xlsx

Thank you very much erik

Developer
Sep 2, 2009 at 6:14 PM

Hmm... Sorry, but could you please explain again with which file the bug occurs.

before-test_xls.xlsx opens fine in MS Office Excel 2007

after-test_xls.xlsx is corrupt when I try to open in MS Office Excel 2007

But both files look like they have been saved from Excel ? How should I understand the bug?

Sep 2, 2009 at 6:17 PM

before-test_xls.xlsx is a file which i made with ms office

my script (see top of page) open it fine and save it without any modifications

the saved file is after-test_xls.xlsx

 

and yes it is corrupted... i do not understand why :-(

Developer
Sep 2, 2009 at 6:34 PM
Edited Sep 2, 2009 at 6:36 PM

Strange. I have run this simple plain read/write script:

$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load('before-test_xls.xlsx');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel, "Excel2007");
$objWriter->save('write.xlsx');

Generated file is here: http://koyama.dk/demos/PHPExcel/67760/write.xlsx

File seems ok? Do you think it could be a problem with the zip extension on your server? Are you running PHP 5.2.8 on Windows? We know there is a problem with the zip extension bundled in that version of PHP?

Sep 3, 2009 at 4:54 PM

Do you think it could be a problem with the zip extension on your server? Are you running PHP 5.2.8 on Windows? We know there is a problem with the zip extension bundled in that version of PHP?

YES! that was it

I tried online, on my shared hosting and it worked!

too bad this thing with the zip extension

thank you very much koyama :-)