PHP code example of zeroibc / excel

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

    

zeroibc / excel example snippets




Final\Excel\Excel;

date_default_timezone_set('PRC');

$data = Excel::readExcelFile('./1.xlsx', ['id' => '编号', 'name' => '姓名', 'date' => '日期']);

//处理日期
array_walk($data, function (&$item) {
    $item['date'] = Excel::convertTime($item['date'], 'Y-m-d');
});

var_dump($data);

//如果数据量大,建议用csv格式
$data = Excel::readExcelFile('./1.csv', ['id' => '编号', 'name' => '姓名', 'date' => '日期'], 1, 1, '', 'GBK');


$data = array(
    array('id' => 1, 'name' => 'Jack', 'age' => 18, 'date'=>'2017-07-18']),
    array('id' => 2, 'name' => 'Mary', 'age' => 20, 'date'=>'2017-07-18']),
    array('id' => 3, 'name' => 'Ethan', 'age' => 34, 'date'=>'2017-07-18']),
);

$map = array(
    'title'=>[
        'id' => '编号',
        'name' => '姓名',
        'age' => '年龄',
     ],
);

$file = 'user' . date('Y-m-d');

Excel::exportExcel($data, $map, $file, '用户信息');