duanbi5906 2016-07-11 17:20
浏览 62
已采纳

如何将PHPExcel生成的文件从PHP页面传递到另一个PHP页面?

I have a main php page (portal.php) where the user selects a date range to obtain some data. Then the main page POSTs to another small php page (downloadInExcel.php) using AJAX to perform a MYSQL query and saves the results in an Excel sheet using PHPExcel. I want to download the generated Excel file in the browser. This works if I load the small php page with PHPExcel in it (downloadInExcel.php). But I want to download the Excel page in the main php page (portal.php). Is there a way to pass the generated Excel sheet in downloadInExcel.php to portal.php?

Please give as much detail as possible to help me write the code.

Thanks a lot!

Here is the part of my code where I download the excel sheet:

header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="results.xls"');
header("Cache-Control: max-age=0");
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_get_clean();
$objWriter->save("php://output");
ob_end_flush();
  • 写回答

1条回答 默认 最新

  • douyoufan7881 2016-07-11 17:41
    关注

    You don't need to pass the Excel from one page to another, that wouldn't make any sense.

    Instead you can save it in the server inside that page you call within AJAX and return the location and file name where you saved it. This way you can process it in your main page.

    You can also call the download page not using AJAX but calling it directly in a new tab/window.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀