项目需求必须是导出xlsx,在win直接过,迁移到linux直接傻眼,网上搜索半天最多的就是将xlsx改成xls,对于没有特定需求的确实够用,奈何项目需求卡死啊!!!
PHP:7.3.8、Apache、tp5
如果想用xls,我就是把xlsx改成xls,Excel2007改成Excel5就可以,网上说还要加入一些头文件啥的,不是很懂,小白还没有去深入研究,我的phpoffice是直接用composer导入的
win系统下,直接一次过,不需要改东西:
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xlsx"');
header("Content-Disposition:attachment;filename=$fileName.xlsx");
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');
linux(查看服务器报错:Class 'ZipArchive' not found):
后面就在网上搜到了这句:\PHPExcel_Settings::setZipClass(\PHPExcel_Settings::PCLZIP);
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xlsx"');
header("Content-Disposition:attachment;filename=$fileName.xlsx");
\PHPExcel_Settings::setZipClass(\PHPExcel_Settings::PCLZIP); //就是加了这一句
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');