Created
September 13, 2018 11:53
-
-
Save damijanc/c23d7358d298898c96d4d7b5eec0d616 to your computer and use it in GitHub Desktop.
Example on how to download an Excel file created with PhpSpreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$streamedResponse = new StreamedResponse(); | |
$streamedResponse->setCallback(function () { | |
$spreadsheet = //create you spreadsheet here; | |
$writer = new Xlsx($spreadsheet); | |
$writer->save('php://output'); | |
}); | |
$streamedResponse->setStatusCode(Response::HTTP_OK); | |
$streamedResponse->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); | |
$streamedResponse->headers->set('Content-Disposition', 'attachment; filename="your_file.xlsx"'); | |
return $streamedResponse->send();` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would add
fastcgi_finish_request();
at the end: