您的位置:首页 > 编程语言 > PHP开发

PHPExcel 导出问题 500 Internal Server Error

2018-03-21 10:51 776 查看
最近phpExcel导出遇到一个问题,本地导出Excel时,跳转出页面问题:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.More information about this error may be available in the server error log.查了一圈,问题定位在Excel最后的header代码块,下面是原来线上的写法及本地替换写法://....引用PHPExcel类
//include_once S_ROOT.'/../extensions/phpexcel/PHPExcel.php';
//...创建一个Excel
//$objPHPExcel = new \PHPExcel();
//...设置Excel属性
//$objPHPExcel->setActiveSheetIndex(0);
//$objActSheet = $objPHPExcel->getActiveSheet();
//...
//导出Excel
$name = '未发货'.date('Ymd');

     /*线上代码
header('Content-Type : application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$name.'.xls"');
*/
/*本地测试代码*/
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$name.'.xls"');
header("Content-Transfer-Encoding: binary");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");

$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');线上代码到我本地导出报错,具体什么原因先不管它,在这里记录一下。
同事说可能是导出的文件名是中文导致的,线上代码的文件名urldecode($name)一下,暂时没验证,记录下
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐