composer require jianyan74/php-excel
引入
use jianyan\excel\Excel;
// [名称, 字段名, 类型, 类型规则] $header = [ ['ID', 'id', 'text'], ['手机号码', 'mobile'], // 规则不填默认 text ['openid', 'fans.openid', 'text'], ['昵', 'fans.nickname', 'text'], ['关注 /扫描', 'type', 'selectd', [1 => '关注', 2 => '扫描']], ['性别', 'sex', 'function', function($model){ return $model['sex'] == 1 ? '男' : '女'; }], ['创建时间', 'created_at', 'date', 'Y-m-d'], ]; $list = [ [ 'id' => 1, 'type' => 1, 'mobile' => '18888888888', 'fans' => [ 'openid' => '123', 'nickname' => '昵称', ], 'sex' => 1, 'create_at' => time(), ] ];
// 简单使用 return Excel::exportData($list, $header); // 定制 默认导出 xlsx 支持 : xlsx/xls/html/csv return Excel::exportData($list, $header, '测试', 'xlsx'); // 另外一种导出 csv 方式 return Excel::exportCsvData($list, $header);
/** * 导入 * * @param $filePath 文件路径 * @param int $startRow 开始行数 默认 1 * @return array|bool|mixed */ $data = Excel::import($filePath, $startRow);
1 chensong004 2019-06-19 16:14:08 +08:00 via Android 马一下,正好能用到 |
![]() | 2 jianyan74 OP github 地址: https://github.com/jianyan74/php-excel |
3 payton93 2019-06-20 15:54:23 +08:00 马一下+1 |