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.

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?