rap2hpoutre / fast-excel

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

Download not working from Livewire #268

Open dfe-dev opened 2 years ago

dfe-dev commented 2 years ago

I'm using fast-excel 3.2.0 and Laravel v8.28.1. When I try the basic code to export all users, nothing happens. No file downloaded. I'm calling the class from a Livewire component. Should I add something else to make this component work?

Best regards.

dfe-dev commented 2 years ago

This is the function from the Livewire component:

public function queryExport($format) { if($format == 'Xlsx') {

        // Export all
        return (new FastExcel(Sello::all()))->download('sellos.xlsx');
    }    
}    

Now I get a download, but the file has another name: download.txt, instead of "sellos.xlsx"

woutervandamme commented 2 years ago

try this:

return response()->streamDownload(function () { return (new FastExcel(Sello::all())) ->export('php://output'); }, sprintf('sellos-%s.xlsx', date('Y-m-d')));

obrunsmann commented 1 year ago

try this:

return response()->streamDownload(function () { return (new FastExcel(Sello::all())) ->export('php://output'); }, sprintf('sellos-%s.xlsx', date('Y-m-d')));

But CSV download seems so unfortunately not possible

foxkyo commented 1 year ago

try this:

return response()->streamDownload(function () { return (new FastExcel(Sello::all())) ->export('php://output'); }, sprintf('sellos-%s.xlsx', date('Y-m-d')));

the same problem with download.txt

    $list = collect([
        [ 'id' => 1, 'name' => 'Jane' ],
        [ 'id' => 2, 'name' => 'John' ],
    ]);

    return response()->streamDownload(function () {
        return (new FastExcel($list))
            ->export('php://output');
    }, sprintf('leads-%s.xlsx', date('Y-m-d')));

google chrome return ERR_INVALID_RESPONSE

Laravel v10.17.1 (PHP v8.1.9) "livewire/livewire": "^2.12", "rap2hpoutre/fast-excel": "^5.2"

foxkyo commented 1 year ago

try this: return response()->streamDownload(function () { return (new FastExcel(Sello::all())) ->export('php://output'); }, sprintf('sellos-%s.xlsx', date('Y-m-d')));

the same problem with download.txt

    $list = collect([
        [ 'id' => 1, 'name' => 'Jane' ],
        [ 'id' => 2, 'name' => 'John' ],
    ]);

    return response()->streamDownload(function () {
        return (new FastExcel($list))
            ->export('php://output');
    }, sprintf('leads-%s.xlsx', date('Y-m-d')));

google chrome return ERR_INVALID_RESPONSE

Laravel v10.17.1 (PHP v8.1.9) "livewire/livewire": "^2.12", "rap2hpoutre/fast-excel": "^5.2"

return response()->streamDownload(function () {

  $list = collect([
      [ 'id' => 1, 'name' => 'Jane' ],
      [ 'id' => 2, 'name' => 'John' ],
  ]);

    return (new FastExcel($list))
        ->export('php://output');
}, sprintf('leads-%s.xlsx', date('Y-m-d')));

solved