I'm using PhpSpreadsheet to generate Excel (.xls) file.
then I realize the mimetype of the generated file was application/vnd.ms-office.
Test with two methods:
Using this to direct download to server dir:
<?php
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xls($spreadsheet);
$filename = 'name-of-the-generated-file.xls';
$writer->save(FCPATH . 'extracted/' . $filename);
and using this to download with browser
<?php
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xls($spreadsheet);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="name-of-the-generated-file.xls"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
I check the generated file with
echo mime_content_type('name-of-the-generated-file.xls');
both of code generate application/vnd.ms-office mime.
how to generate spreadsheet with application/vnd.ms-excel instead of application/vnd.ms-office?