Fast Excel is a Laravel package for importing and exporting spreadsheets. It provides an elegant wrapper around Spout—a PHP package to read and write spreadsheet files in a quick and scalable way. It is capable of processing large files, all while keeping the memory usage low.
Here’s an example of exporting models or collections to an Excel file:
1use Rap2hpoutre\FastExcel\FastExcel; 2use App\User; 3 4// Export a User model 5$users = User::all(); 6(new FastExcel($users))->export('file.xlsx'); 7 8// Export a collection Collection 9$list = collect([10 [ 'id' => 1, 'name' => 'Jane' ],11 [ 'id' => 2, 'name' => 'John' ],12]);13 14(new FastExcel($list))->export('file.xlsx');
You can use the download method to force the user’s browser to download a file:
1return (new FastExcel(User::all()))->download('file.xlsx');
You can also import and export multiple sheets:
1$sheets = new SheetCollection([2 User::all(),3 Project::all()4]);5(new FastExcel($sheets))->export('file.xlsx');
Learn More
You can learn more about this package, get full installation instructions, and view the source code on GitHub at rap2hpoutre/fast-excel.
0 comments:
Post a Comment
Thanks