Fast Excel Package for Laravel


December 17th, 2020

Fast Excel Package for Laravel

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;
4// Export a User model
5$users = User::all();
6(new FastExcel($users))->export('file.xlsx');
8// Export a collection Collection
9$list = collect([
10 [ 'id' => 1, 'name' => 'Jane' ],
11 [ 'id' => 2, 'name' => 'John' ],
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()
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.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.