GitHub - rap2hpoutre/fast-excel: ? Fast Excel import/export for Laravel [WIP]
source link: https://github.com/rap2hpoutre/fast-excel
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
readme.md
Laravel Fast Excel
Fast Excel import/export for Laravel, thanks to Spout. See benchmarks below.
Quick start
Install via composer:
composer require rap2hpoutre/fast-excel
Export a Model to .xlsx
file:
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all(); // Export all users (new FastExcel($users))->export('file.xlsx');
Usage
Use Fast Excel to import and export Excel files.
Export
You can export a Model or a Collection:
$list = collect([ [ 'id' => 1, 'name' => 'Jane', ], [ 'id' => 1, 'name' => 'John', ], ]); (new FastExcel($list))->export('file.xlsx');
You can export xlsx
, ods
and csv
:
$invoices = App\Invoice::orderBy('created_at', 'DESC')->get(); (new FastExcel($invoices))->export('invoices.csv');
Import
import
returns a Collection:
$collection = (new FastExcel)->import('file.xlsx');
Import a csv
with a specific delimiter and enclosure characters.
$collection = (new FastExcel)->configureCsv(';', '#')->import('file.csv');
Why?
Laravel Fast Excel is intended at being Laravel-flavoured Spout: a simple, but elegant wrapper around Spout with the goal of simplifying imports and exports.
It could be considered as a faster (and memory friendly) alternative to Laravel Excel, with many less features. Use it only for very simple tasks.
Benchmarks
Tested on a MacBook Pro 2015 2,7 GHz Intel Core i5 16 Go 1867 MHz DDR3. Testing a XLSX export for 10000 lines, 20 columns with random data, 10 iterations. Don't trust benchmarks.
Average memory peak usage Execution time Laravel Excel 123.56 M 11.56 s Laravel Fast Excel 2.09 M 2.76 s
Still, remember that Laravel Excel has many more feature. Please help me improve benchmarks, more tests re coming. Feel free to criticize.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK