Monday, March 20, 2017

How to export the excel file with laravel?

I've tried maatwebsite to excel export data from the database but once downloaded, the file cannot be opened ,

    $users = user::select('username', 'email')->get();
 // work on the export
      Excel::create('users', function($excel) use ($users){
         $excel->sheet('sheet 1', function($sheet) use ($users)
            {
                $sheet->fromArray($users);
            });
        })->download('xlsx');

When the file is open :

enter image description here

please help me :(

Note: I've added:

Maatwebsite\Excel\ExcelServiceProvider::class,

'Excel' => Maatwebsite\Excel\Facades\Excel::class,



via Siti Rahmah

Advertisement