PHP code example of dashingunique / excel

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

    

dashingunique / excel example snippets


use dashingUnique\excel\DashingExcel;
use app\model\User;

// Load users
$users = new User()->select();
$users = uniqueCollection($users);
// Export all users
(new DashingExcel($users))->export('file.csv');

$users = new User()->select();
$users = uniqueCollection($users);
(new DashingExcel($users))->export('users.csv', function ($user) {
    return [
        'Email' => $user['email'],
        'First Name' => $user['firstname'],
        'Last Name' => strtotime($user['create_time']),
    ];
});

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

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