I'm working on a project where I need to generate Excel files with bank information (reports).
I was able to do this with the PhpSpreadsheet library, however the file is saved on the server, and when I add the headers to force the file to be downloaded, it is corrupted. If shooting the headers it generates normally.
The headers I'm using:
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');