All Projects → rap2hpoutre → Fast Excel

rap2hpoutre / Fast Excel

Licence: mit
🦉 Fast Excel import/export for Laravel

Projects that are alternatives of or similar to Fast Excel

Tabtoy
高性能表格数据导出器
Stars: ✭ 1,302 (+10.06%)
Mutual labels:  excel, csv, xlsx, fast
eec
A fast and lower memory excel write/read tool.一个非POI底层,支持流式处理的高效且超低内存的Excel读写工具
Stars: ✭ 93 (-92.14%)
Mutual labels:  fast, csv, excel, xlsx
dbd
dbd is a database prototyping tool that enables data analysts and engineers to quickly load and transform data in SQL databases.
Stars: ✭ 30 (-97.46%)
Mutual labels:  csv, excel, xlsx
Laravel Nova Excel
🚀 Supercharged Excel exports for Laravel Nova Resources
Stars: ✭ 259 (-78.11%)
Mutual labels:  excel, laravel, laravel-package
J
❌ Multi-format spreadsheet CLI (now merged in http://github.com/sheetjs/js-xlsx )
Stars: ✭ 343 (-71.01%)
Mutual labels:  excel, csv, xlsx
MiniExcel
Fast, Low-Memory, Easy Excel .NET helper to import/export/template spreadsheet
Stars: ✭ 996 (-15.81%)
Mutual labels:  csv, excel, xlsx
sheet2dict
Simple XLSX and CSV to dictionary converter
Stars: ✭ 206 (-82.59%)
Mutual labels:  csv, excel, xlsx
Spout
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
Stars: ✭ 3,861 (+226.37%)
Mutual labels:  csv, xlsx, fast
Laravel Report Generator
Rapidly Generate Simple Pdf, CSV, & Excel Report Package on Laravel
Stars: ✭ 380 (-67.88%)
Mutual labels:  excel, csv, laravel
Laracsv
A Laravel package to easily generate CSV files from Eloquent model
Stars: ✭ 583 (-50.72%)
Mutual labels:  excel, csv, laravel
Sheetjs
📗 SheetJS Community Edition -- Spreadsheet Data Toolkit
Stars: ✭ 28,479 (+2307.35%)
Mutual labels:  excel, csv, xlsx
Tableexport
The simple, easy-to-implement library to export HTML tables to xlsx, xls, csv, and txt files.
Stars: ✭ 781 (-33.98%)
Mutual labels:  excel, csv, xlsx
Php Ext Xlswriter
🚀 PHP Extension for creating and reader XLSX files.
Stars: ✭ 1,734 (+46.58%)
Mutual labels:  excel, xlsx, laravel
exoffice
Library to parse common excel formats (xls, xlsx, csv)
Stars: ✭ 31 (-97.38%)
Mutual labels:  csv, excel, xlsx
Filecontextcore
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Stars: ✭ 91 (-92.31%)
Mutual labels:  excel, csv, xlsx
Sq
swiss-army knife for data
Stars: ✭ 275 (-76.75%)
Mutual labels:  excel, csv, xlsx
Myexcel
MyExcel, a new way to operate excel!
Stars: ✭ 1,198 (+1.27%)
Mutual labels:  excel, csv, xlsx
Dbwebapi
(Migrated from CodePlex) DbWebApi is a .Net library that implement an entirely generic Web API (RESTful) for HTTP clients to call database (Oracle & SQL Server) stored procedures or functions in a managed way out-of-the-box without any configuration or coding.
Stars: ✭ 84 (-92.9%)
Mutual labels:  excel, csv, xlsx
Meza
A Python toolkit for processing tabular data
Stars: ✭ 374 (-68.39%)
Mutual labels:  excel, csv, xlsx
Rows
A common, beautiful interface to tabular data, no matter the format
Stars: ✭ 739 (-37.53%)
Mutual labels:  excel, csv, xlsx

Version License Build Status Scrutinizer Code Quality Codacy Badge Total Downloads

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');

Export

Export a Model or a Collection:

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

(new FastExcel($list))->export('file.xlsx');

Export xlsx, ods and csv:

$invoices = App\Invoice::orderBy('created_at', 'DESC')->get();
(new FastExcel($invoices))->export('invoices.csv');

Export only some attributes specifying columns names:

(new FastExcel(User::all()))->export('users.csv', function ($user) {
    return [
        'Email' => $user->email,
        'First Name' => $user->firstname,
        'Last Name' => strtoupper($user->lastname),
    ];
});

Download (from a controller method):

return (new FastExcel(User::all()))->download('file.xlsx');

Import

import returns a Collection:

$collection = (new FastExcel)->import('file.xlsx');

Import a csv with specific delimiter, enclosure characters and "gbk" encoding:

$collection = (new FastExcel)->configureCsv(';', '#', '\n', 'gbk')->import('file.csv');

Import and insert to database:

$users = (new FastExcel)->import('file.xlsx', function ($line) {
    return User::create([
        'name' => $line['Name'],
        'email' => $line['Email']
    ]);
});

Facades

You may use FastExcel with the optional Facade. Add the following line to config/app.php under the aliases key.

'FastExcel' => Rap2hpoutre\FastExcel\Facades\FastExcel::class,

Using the Facade, you will not have access to the constructor. You may set your export data using the data method.

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

FastExcel::data($list)->export('file.xlsx');

Global helper

FastExcel provides a convenient global helper to quickly instantiate the FastExcel class anywhere in a Laravel application.

$collection = fastexcel()->import('file.xlsx');
fastexcel($collection)->export('file.xlsx');

Advanced usage

Export multiple sheets

Export multiple sheets by creating a SheetCollection:

$sheets = new SheetCollection([
    User::all(),
    Project::all()
]);
(new FastExcel($sheets))->export('file.xlsx');

Use index to specify sheet name:

$sheets = new SheetCollection([
    'Users' => User::all(),
    'Second sheet' => Project::all()
]);

Import multiple sheets

Import multiple sheets by using importSheets:

$sheets = (new FastExcel)->importSheets('file.xlsx');

You can also import a specific sheet by its number:

$users = (new FastExcel)->sheet(3)->import('file.xlsx');

Export large collections with chunk

Export rows one by one to avoid memory_limit issues using yield:

function usersGenerator() {
    foreach (User::cursor() as $user) {
        yield $user;
    }
}

// Export consumes only a few MB, even with 10M+ rows.
(new FastExcel(usersGenerator()))->export('test.xlsx');

Add header and rows style

Add header and rows style with headerStyle and rowsStyle methods.

$header_style = (new StyleBuilder())->setFontBold()->build();

$rows_style = (new StyleBuilder())
    ->setFontSize(15)
    ->setShouldWrapText()
    ->setBackgroundColor("EDEDED")
    ->build();

return (new FastExcel($list))
    ->headerStyle($header_style)
    ->rowsStyle($rows_style)
    ->download('file.xlsx');

Why?

FastExcel 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 less features. Use it only for 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, 2018-04-05. Don't trust benchmarks.

Average memory peak usage Execution time
Laravel Excel 123.56 M 11.56 s
FastExcel 2.09 M 2.76 s

Still, remember that Laravel Excel has many more features.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].