PHPExcel exception: “Could not close zip file … ”

馋奶兔 提交于 2019-12-13 13:01:30

问题


I am using XAMPP a Mac for local development, but I used this code at work (using Windows and an otherwise identical development environment) and it worked fine:

$objPHPExcel = new PHPExcel();
$sheet       = $objPHPExcel->createSheet();
$sheet->fromArray($a);
...
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save('P:/Projects/Mess3/Sadness.xlsx');
$objWriter->save('/Users/tjb1982/Desktop/sadness.xlsx');

The commented-out text works with my Windows system at work. I tried to output the file to 'php://output' and got a garbled mess (is that what is to be expected?).

I can't seem to find anyone who is experiencing this problem outside of those who had permissions problems or had the file open when they were trying to save it. Please help!


回答1:


I was getting the same error "Cannot close zip file.." and realized it didn't have permissions to write to that directory. Check your write permissions. (IIS8 + php + mysql + oracle)

Once i allowed write permissions problem was immediately fixed.




回答2:


Generally this means one of 3 things:

The directory where you're trying to save the file doesn't exist
The directory/file has permissions that preclude you from writing to it
The file is already open in some other application, or has a lock on it 



回答3:


I had the same problem, just added the path in the save method and it worked

$objWriter->save(dirname(FILE)."dir1"."/".$file.".xlsx");




回答4:


I found that this problem is caused when you execute the code once and then open the outputted excel file with Office excel. Try closing the file in excel and then try! Hope this helps!




回答5:


I had the same problem, actually you have to modify the basic rights of reading and writing given to your PHPWord directory:

chmod -R 777 PHPWord/


来源:https://stackoverflow.com/questions/7068419/phpexcel-exception-could-not-close-zip-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!