phpexcel导出乱码

在输出到浏览器时,要在head前加ob_end_clean();参考此文

ob_end_clean();
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$name.'.xls"');
header('Cache-Control: max-age=0');

$objWriter->save('php://output');

ob_end_clean() - 清空缓冲区并关闭输出缓冲,因为此时的输出缓存里可能有其它内容,这样和phpexcel的输出混在一起,那么就不是需要的excel文件了。

posted @ 2016-07-14 06:43  半山th  阅读(513)  评论(0编辑  收藏  举报