PHPExcel in CakePHP: error - excel file is incompatible or corrupt

I use Cake; since I open the excel file in the browser using the generate function:

I get this error from Microsoft Excel:

Excel cannot open the .xlsx Group List file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the file format.

I tried to remove the spaces in the file name after downloading from the browser and open it again, it shows the same error as above. Has anyone experienced this and decided? or any clue to what's going on?

Basically the excel file opens but is empty due to the error above. I read a similar problem that says removing the place at the end of the tag ?>in one of the component files. But I do not know which component file ..?

PS I am using Microsoft Excel 2010, could this be the reason? Is PHPExcel currently working for "Microsoft Excel 2010"?

+5
source share
4 answers

PHPExcel Excel2007 Writer must generate valid xlsx files that can be read by Excel 2007, Excel 2010, and Excel 2003 with the compatibility pack. I actually do most of my tests using Excel2010 and Excel2003.

, , - , , . , . , .

xlsx xml , , ( PK-), ( , ). , .

Windows, ZipArchive (php_zip.dll), . SVN- PCLZip ZipArchive.

- , PHPExcel .

+2

/ excel

PDF

<?php 
 header("Content-type: application/pdf"); 
 echo $content_for_layout; 
?> 
+1

?

<?php
$file="test.xls";
$test="<table border=1><tr><td>Cell 1</td><td>Cell 2</td></tr></table>";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $test;
?>

0

Excel ( PHPExcel CakePHP):

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.'myreportname.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

$this->render(false);
  • $objPHPExcel | , PHPExcel()

  • $this- > Render (); | , , Excel

0

All Articles