lavarel php5.2,laravel 5.2 使用phpexcel 导出 excel文件出问题

1.出现的问题

bVLtUk?w=1324&h=568

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 大概信息就这样 如有需要可以提供更多信息

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

Laravel 有现成封装的 excel 的库吧,不需要想你这么写吧

将第二个

ob_end_clean();

删除就好了,本地测试可以下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值