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();` |
Any way to use id "standalone" without the Symfony components?
Any way to use id "standalone" without the Symfony components?
<?php
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="GeneratedFile.xlsx"');
header('Cache-Control: max-age=0');
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
Any way to use id "standalone" without the Symfony components?
<?php $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Hello World !'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="GeneratedFile.xlsx"'); header('Cache-Control: max-age=0'); $writer = new Xlsx($spreadsheet); $writer->save('php://output');
I would add fastcgi_finish_request();
at the end:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It was an excerpt from the code, but thank you for pointing it out. I hope that no one will just blindly copy and paste it.