今天遇到一个很奇怪的问题,同样的导出方法,在同一个项目中,一处正常,另一处乱码Untitled Spreadsheet Unknown CreatorUnknown Creator,乱码如下:
最后找到一个解决方法,在header前增加
ob_end_clean();
问题解决
$objPHPExcel->getActiveSheet()->setTitle('会员数据');
$objPHPExcel->setActiveSheetIndex(0);
ob_end_clean();
header("Content-type: text/html; charset=utf-8");
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="会员数据-截至'.date("Y-m-d H:i:s").'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;