laravel excel怎样导出数据库中的数据
2个回答
展开全部
将需要导出的内容封装到数组里面,然后一次性导出,示例代码如下:
function DataList(Excel $excel) {
$info = $this->test->select('id','name','sex','mobile','hobby')->get();
foreach ($info as $key => $value) {
$export[] = array(
'ID' => $value['id'],
'姓名' => $value['name'],
'性别' => $value['mobile'],
'电话' => $value['mobile'],
'爱好' => $value['hobby'],
);
}
$tab_name = 'users';
$excel->create($name, function($excel) use ($export) {
$excel->sheet('export', function($sheet) use ($export) {
$sheet->fromArray($export);
});
})->export('xls');
}
function DataList(Excel $excel) {
$info = $this->test->select('id','name','sex','mobile','hobby')->get();
foreach ($info as $key => $value) {
$export[] = array(
'ID' => $value['id'],
'姓名' => $value['name'],
'性别' => $value['mobile'],
'电话' => $value['mobile'],
'爱好' => $value['hobby'],
);
}
$tab_name = 'users';
$excel->create($name, function($excel) use ($export) {
$excel->sheet('export', function($sheet) use ($export) {
$sheet->fromArray($export);
});
})->export('xls');
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询