一、优势:导出时间短;
三、安装库文件
composer命令:composer require viest/php-ext-xlswriter-ide-helper:dev-master
或者直接下载包放在vendor目录下(通过composer下载不了的情况) :
https://github.com/viest/php-ext-xlswriter-ide-helper
代码示例
/**
*
* 导出EXCEL数据通用方法
* @author fff
* @column 单元格头
* @data 导出数据
* @name 导出数据名称
*
*/
public function downExcel(array $column, array $data, $name) {
set_time_limit(0);
ini_set('memory_limit', '10240M');
//先处理为索引数组,不认关联数组;列名顺序要与列值顺序保持一致
$new_data = [];
foreach ($data as $key => $value) {
$new_data[] = array_values($value);
}
$path = app()->getRootPath() . 'public' . DIRECTORY_SEPARATOR. 'storage'. DIRECTORY_SEPARATOR. 'exportExcel';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$callStartTime = microtime(true);
$config = ['path' => $path]; //设置文件保存路径
$excel = new \Vtiful\Kernel\Excel($config);
// fileName 会自动创建一个工作表,你可以自定义该工作表名称,工作表名称为可选参数
$filePath = $excel->fileName($name . '.xlsx', 'Sheet1')
->header($column) // 设置表首行名称
->data($new_data)
->output();
if (!empty($filePath)) {
return download($filePath, $name . '.xlsx');
} else {
return errorJson('导出数量超过30W条,无法下载');
}
}