rap2hpoutre / fast-excel

🦉 Fast Excel import/export for Laravel
MIT License
2.09k stars 245 forks source link

Download not working when using laravel octane #239

Closed mcolominas closed 1 year ago

mcolominas commented 2 years ago

I have tried to download the excel following the instructions:

return (new FastExcel(Users::all()))->download('users.xlsx');

But the file is not downloaded, it only shows the binary content in the browser: ��4:����Ci[l���-���+���01�M�F,J�m�Q� (��a�R���Onޘ� ڃU�&<& ytr��aH�|�B��<���&

I have run this same code using normal laravel, and it has downloaded without problems, but when using the octane laravel, as I have indicated, it only shows the binary result in the browser

If anyone knows of any alternative to download it, I will be grateful if you tell me.

mcolominas commented 2 years ago

I have managed to make it download, but I don't think it is the best option:

$export = (new FastExcel(Users::all()))->download('users.xlsx');

$export->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', true);
$export->headers->set('Content-Disposition', 'attachment; ' .
    'filename="' . rawurldecode($file_name) . '"; ' .
    'filename*=UTF-8\'\'' . rawurldecode($file_name), true);
$export->headers->set('Cache-Control', 'max-age=0', true);
$export->headers->set('Pragma', 'public', true);

return $export;