I’m using PHPSpreadsheet to generate an Excel Workbook and then I send it to be directly opened or downloaded.
I Edge, IE, it works just fine, but for some reason in FF (I’m running V69) when you directly open it the dialog show the file name properly with an .xlsx, but the dialog is stating an html document? When you directly open it the filename has an appended .html to it, but if you download it, it does not?!
This is the code that I am using to generate the ‘virtual’ workbook and serve it up form open/download
$filename = 'Statistics_' . date('Ymd\THis') . '.xlsx';
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$response = Yii::$app->getResponse();
$headers = $response->getHeaders();
$headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //xlsx
$headers->set('Content-Disposition', 'attachment;filename="'.$filename.'"');
$headers->set('Cache-Control: max-age=0');
ob_start();
$writer->save("php://output");
$content = ob_get_contents();
ob_clean();
return $content;
Would anyone happen to know what I’m doing wrong?