Reputation: 565
I have a script that creates an Excel file and exports it. This was running fine in PHP5.6 but since upgrading to PHP7.0 this is not working anymore.
I've found a couple related issues where people suggested installing php7.0-zip
, but this did not solve the issue.
Also getting the same error on different browsers.
It happens after $objWriter->save('php://output');
require_once 'includes/PHPExcel/PHPExcel.php';
require_once 'includes/PHPExcel/PHPExcel/Writer/Excel2007.php';
$title = 'Export'. date('d-m-Y');
$count = $_GET['count'];
$objPHPExcel = new PHPExcel();
$objWorkSheet = $objPHPExcel->createSheet(0);
foreach ($_SESSION['tableheaders'][$count] as $column => $val) {
$objWorkSheet->setCellValueByColumnAndRow($column, 1, $val);
$objWorkSheet->getStyleByColumnAndRow($column, 1)->getFont()->setBold(true);
$objWorkSheet->getStyleByColumnAndRow($column, 1)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('C2C2C2');
}
$lastColumnIndex = 'A';
foreach ($_SESSION['tablerows'][$count] as $row => $innerArr) {
foreach ($innerArr as $column => $val) {
$objWorkSheet->setCellValueByColumnAndRow($column, $row + 2, $val);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($column)->setAutoSize(true);
$lastColumnIndex = $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($column)->getColumnIndex();
}
}
$objPHPExcel->getActiveSheet()->freezePane('A2');
$objPHPExcel->getActiveSheet()->setAutoFilter("A1:{$lastColumnIndex}1");
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename='{$title}.xlsx'");
// If I die here, the error does not happen but my Excel file is damaged/empty.
$objWriter->save('php://output');
Upvotes: 2
Views: 9273
Reputation: 31
Phpexcel does't work well with PHP 7.0
Try upgrading from Phpexcel to phpSpreadsheet .
phpSpreadsheet works very well with php latest versions .
Upvotes: 0
Reputation: 565
Found the problem, in PHPExcel v1.8.0
in file PHPExcel/Calculation/Functions.php
on line 581 there is a break;
after a return
statement which is causing an error.
This was fixed in the latest (and last) version 1.8.1
Upvotes: 8