最近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代码块,逐步排查,最后是一个空格导致的:
header('Content-Type : application/vnd.ms-excel');//这里的冒号前面多了个空格!!!!!!!!!!!去掉就好了
public function actionExport()
{ //....引用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"');
*/
/*本地测试代码*/
$fileName = '未发货'.date('Ymd').".xls";
$fileName = iconv("utf-8", "gb2312", $fileName);//中文编码处理
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=\"$fileName\"");
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output'); }