PHP code example of gito-me / fast-excel

1. Go to this page and download the library: Download gito-me/fast-excel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gito-me / fast-excel example snippets


use Rap2hpoutre\FastExcel\FastExcel;
use App\User;

// Load users
$users = User::all();

// Export all users
(new FastExcel($users))->export('file.xlsx');

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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