首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHPSpreadsheet在浏览器中下载xlsx

PHPSpreadsheet在浏览器中下载xlsx
EN

Stack Overflow用户
提问于 2020-06-09 21:01:23
回答 2查看 640关注 0票数 0

我希望在浏览器上下载生成的Xlsx文件,但当我执行此代码时,请求启动时没有错误,但什么也没有发生

代码语言:javascript
运行
复制
   header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    header('Content-Disposition: attachment; filename='.basename($pathfile).'');
    header('Cache-Control: max-age=0');


    File::setUseUploadTempDirectory(true);

    $objWriter = IOFactory::createWriter($objWorkBookExcel, 'Xlsx');

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

header

当我使用这个的时候:

代码语言:javascript
运行
复制
$objWriter->save($pathfile);

我的文件在我的服务器上生成

EN

回答 2

Stack Overflow用户

发布于 2020-06-09 21:09:00

我推荐使用PHPOffice的进化版PHPspreedsheet

试一试:

代码语言:javascript
运行
复制
$objWriter = io_factory::createWriter($objPHPExcel, 'Xlsx');


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/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=nameoffile.xlsx");
header("Content-Transfer-Encoding: binary ");

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

如果您使用PHPExcel:

代码语言:javascript
运行
复制
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
$objWriter->save('php://output');
die();
票数 0
EN

Stack Overflow用户

发布于 2020-06-09 21:35:00

现在我在这里

代码语言:javascript
运行
复制
  $objWriter = IOFactory::createWriter($objWorkBookExcel, 'Xlsx');

    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/octet-stream");
    header("Content-Type: application/download");;
    header("Content-Disposition: attachment;filename='nameoffile.xlsx'");
    header("Content-Transfer-Encoding: binary ");

    ob_end_clean();
    ob_start();
    File::setUseUploadTempDirectory(true);
    $objWriter->save('php://output');      
    exit;

Header

但是没有下载的文件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62283244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档