Try using the xlsx extension instead.
xls is an extension for Excel files created with versions before 2003, so I am assuming most online viewers won't bother to support those.
Hi. Please some one help me with this problem. I am using PhpSpreadsheet and making and downloading a simple excel file using following code:
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
public function test(Request $req){
$spreadsheet = new Spreadsheet;
$active_sheet = $spreadsheet->getActiveSheet();
$active_sheet->setCellValue('A1', 'Firstname');
$active_sheet->setCellValue('A2', 'Alex');
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$filename = "alex.xls";
$writer->save(base_path($filename));
return response()->download(base_path('alex.xls'));
}
The process creates a simple excel file with 2 rows and one column. The created file works great and I can show it on both local and web application excel viewers. However when I upload downloaded version of the same file, excel viewers say "Upload excel file with right format". I also tried headers on download method of Reponse and set it to `application/vnd.ms-excel` and also tried some other headers but none work.
Pleaes help me fix it, thank you.
@danimohamadnejad Maybe if you have a file somewhere in your application which starts with an odd character other than <?php This would cause any browser output to be prefixed with a character
Please or to participate in this conversation.