Im trying to export my table player mysql to an excel file with phpspreadsheet. The problem is that when the file is downloaded, when we open the file, we have the html page in the file (with the excel content). Because of that, the file is corrupted. For sure is the return of the controller which doesn't work. But how to do?
Here is the controller:
* @Route("/export", name="doExport", methods={"POST"})
*/
public function export(Connection $conn, ExportExcel $exportExcel, TrainerRepository $trainerRepository, StaffRepository $staffRepository)
{
$exportExcel->exportExcel($conn);
return $this->render('Effectif/home.html.twig', [
'trainers' => $trainerRepository->findBy(['id'=>228]),
'staffs' => $staffRepository->findAll()
]);
}
The image of the problem: enter image description here The complete code for export is here: http://pastebin.fr/61555
$filename = 'joueurs.xlsx';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. $filename);
header('Cache-Control: max-age=0');
$Excel_writer->save('php://output');
}
}
Please don't close the post.