thinkphp3 phpexcel 导出报错乱码清除ob

这里写自定义目录标题

phpexcel 导出部分

		$fileName = '用户信息';
        $date = date("Y-m-d",time());
        $fileName .= "_{$date}.xls";
        $fileName = iconv("utf-8", "gb2312", $fileName);

        $objPHPExcel->setActiveSheetIndex(0);
        ob_end_clean();//清除缓冲区,避免乱码
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=\"$fileName\"");
        header('Cache-Control: max-age=0');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output'); //文件通过浏览器下载


关键语句

ob_end_clean();//清除缓冲区,避免乱码

问题描述

导出Excel时,文件打不开,显示乱码 …unknown creater 需要清除缓存区

上一篇:vue 基于vue-seamless-scroll无缝滚动


下一篇:在 Nuxt中使用滚动组件 vue-seamless-scroll