dimanche 19 avril 2015

PHPExcel Redirect Page After Creating Excel File

I would like to know how to redirect the page after creating a file using PHPExcel. File created is ok but redirection to another page is not. Below are some codes.



$excel -> setActiveSheetIndex(0);
$_SESSION["information"] = "Motor Line Checking Completed.";
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment;filename='".$report_name.".xlsx'");
header("Cache-Control: max-age=0");
$writer = PHPExcel_IOFactory::createWriter($excel, "Excel2007");
$writer -> save('php://output');
exit;
header("Location: ".$_SERVER["HTTP_HOST"]."/../../");
exit;


NOTES:



  • If I remove exit;after save();, xlsx file will be corrupted.

  • If I move header("Location:...");before save();, it will redirect but will not create xlsx.

  • I also tried redirecting using javascript.


What I want is to create xlsx and redirect the page after.


Aucun commentaire:

Enregistrer un commentaire