Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

laravel 5.2 使用phpexcel 导出 excel文件出问题

1.出现的问题
clipboard.png

2.导出代码(首先声明导出使用PHPExcel_IOFactory::createWriter($objExcel, 'Excel5')->save(outpath)导出正常)
`

        //导出的文件名
        $outputFileName =iconv ( 'UTF-8', 'gb2312', date('Y-m-d_H-i-s',time()).'.xls' );
        //文件直接输出到浏览器
        ob_end_clean();
        header ( 'Pragma:public');
        header ( 'Expires:0');
        header ( 'Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header ( 'Content-Type:application/force-download');
        header ( 'Content-Type:application/vnd.ms-excel');
        header ( 'Content-Type:application/octet-stream');
        header ( 'Content-Type:application/download');
        header ( 'Content-Disposition:attachment;filename='. $outputFileName );
        header ( 'Content-Transfer-Encoding:binary');
        ob_end_clean();
        PHPExcel_IOFactory::createWriter($objExcel, 'Excel5')->save('php://output');
        //记录日志
        $this->optionData("导出文件",session('auth')['userName']."执行了导出文件");
        ob_end_clean();
        return '0';`

3.只要使用php://out就不能输出文件就出现1的情况 但是不使用php://out
就没问题
4.现在的需求是导出时,弹出对话框让用户指定保存位置,提高交互的体验,使用 PHPExcel_IOFactory::createWriter($objExcel, 'Excel5')->save(outpath);
导出后保存到public/upload下面了
5.环境 laravel 5.2 php版本5.5 win7 64bit 大概信息就这样 如有需要可以提供更多信息


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

laravel 用的不是这个包吗 maatwebsite/excel


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...