PHP code example of digitools / fast-excel

1. Go to this page and download the library: Download digitools/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/ */

    

digitools / fast-excel example snippets


use Me\FastExcel\FastExcel;

$data = collect([
    ['name' => 'John Doe', 'email' => '[email protected]'],
    ['name' => 'Jane Smith', 'email' => '[email protected]'],
]);

(new FastExcel($data))->export('users.xlsx');

use Me\FastExcel\FastExcel;

$collection = (new FastExcel)->import('users.xlsx');
$collection->each(function ($row) {
    // Process each row
    User::create($row);
});

use Me\FastExcel\FastExcel;

$data = User::all();

(new FastExcel($data))->export('users.xlsx', function ($user) {
    return [
        'Full Name' => $user->name,
        'Email Address' => $user->email,
    ];
});

use Me\FastExcel\FastExcel;

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

use Me\FastExcel\FastExcel;

(new FastExcel(User::query()->cursor()))->export('large-users.xlsx');