Issue
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();
Solution
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.
Answered By - Vladimir Nul Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.