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();