I've got a simple code as the following (docs) :
// Set the headers to a downloadble content
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="nomfichier.xlsx"');
// Initialize spreadsheet
$objPHPExcel = new PhpOffice\PhpSpreadsheet\Spreadsheet();
$objPHPExcel->setActiveSheetIndex(0);
// Get the sheet and set the value of the first cell
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
// Create the .xlsx file and download it
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
$writer->save('/tmp/temp.csv');
Knowing that this code is in the middle of my PHP page, the downloaded content is the whole text of the HTML page trying to fit into my excel file in the first column and not the simple result I'm looking for : Value named ID
in the first cell and first column.
What did I miss? Does this code needs to be contained in it's own file?