1
I am working on a project where I need to generate Excel files with database information (reports).
I managed to do this with the Phpspreadsheet library, but the file is saved to the server, and when I add the headers to force the file to download, it comes corrupted. If I shoot the headers generates normally.
The headlines I’m wearing:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($sheet, 'Xlsx');
$writer->save('php://output');