PHP code example of virgo / excel-aether

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

    

virgo / excel-aether example snippets


//文件名称
$name = 'demo.xls';
//or
$name = 'demo';

//地址
$dir = './excel';
//or
$dir = './excel/';

//标题
$title = 'demo';

//表头
$header = [
    'name' => '姓名',
    'phone' => '电话',
    'address' => '地址'
];

//数据格式
$list = [       //key=>value 格式可以打乱
    ['name' => 'zhang',
     'address' => 'beijing',
     'phone' => '1821',
     'tt' => '333' //与表头字段不同,会自动过滤
     ],
    ['name' => 'wen',
     'address' => 'shanghia',
     'phone' => '1822'
     ],
    ['name' => 'liu',
     'address' => 'chengdu',
     'phone' => '1823'
     ]

];

//或者

//表头
$header = [
    '姓名', '电话', '地址'
];

//数据格式
$list = [
    ['zhang', '1825', 'beijing'],
    ['wen', '1823', 'shengzhen'],
    ['liu', '1822', 'shanghai'],
    ['xu', '1827', 'nancong'],
    ['qian', '1821', 'dongjing'],
];

//使用
$re = \ExcelAether\ExcelAether::ExcelCreateBySpreadsheet($header, $list, $name, $dir, $title);

var_dump($re->getDir().$re->getFileName());