laravel框架设计excel表格式
程序员文章站
2024-01-29 19:36:28
...
安装laravel框架
excel官网
完整laravel5.3案例框架下载
具体代码:
if ($res->code == 1) {
if($query['excel'] == 'Y'){
if(!($res->results)){
return redirect()
->back()
->withErrors('数据为空,请检查报表条件~')
->withInput();
}
$arr[] = ['ID','用户ID','用户名称','数据ID','状态','金额(元)','创建日期'];
$amount = 0.00 ;
$total = count($res->results);
foreach($res->results as $val){
$arr[] =[$val->id,$val->u_id,$val->username,$val->d_id,$val->type,$val->amount,date('Y-m-d',$val->created_at)];
$amount += $val->amount;
}
$arr[] = ['','','','','总额:',$amount];
$arr[] = ['',' ',' ','',''];
$arr[] = ['','总条数',$total,'',''];
$arr[] = ['','总金额',$amount,'备注:',''];
$arr[] = ['','用户注册','','','徒弟收益(11001)',''];
$arr[] = ['','点击任务','','','师傅收益(11002)',''];
$arr[] = ['','任务大厅','','','师爷收益(11003)',''];
$arr[] = ['','徒弟收益','','','代理收益(11004)',''];
$arr[] = ['','徒孙收益','','','股东收益(11005)',''];
$arr[] = ['','代理收益','','',''];
$arr[] = ['','股东收益','','',''];
$arr[] = ['','','','',''];
$arr[] = ['','报表用户',$query['username']];
$arr[] = ['','报表日期',$query['start_date'].'至'.$query['end_date'],];
$arr[] = ['','报表类型:'.$query['type'],'','',''];
$cellData = $arr;
Excel::create('财务报表',function($excel) use ($cellData){
$excel->sheet('财务报表', function($sheet) use ($cellData){
$tot = count($cellData) ;
$sheet->setWidth(array(
'A' => 12,
'B' => 12,
'C' => 12,
'D' => 12,
'E' => 12,
'F' => 12,
'G' => 12,
))->rows($cellData)->setFontSize(12);
//
// $sheet->row($tot-13, function($row) {
// $row->setBackground('#87eabd');
// });
// 数据内容主题 左对齐
$sheet->cells('A1:F'.$tot, function($cells) {
$cells->setAlignment('left');
});
// 菜单 样式
$sheet->cells('A1:G1', function($cells) {
$cells->setAlignment('center');
$cells->setFontWeight('bold');
});
// 数据统计 样式
$sheet->cells('A'.($tot-13).':F'.$tot, function($cells) {
$cells->setAlignment('left');
$cells->setFontWeight('bold');
});
// 备注 右对齐
$sheet->cells('D'.($tot-11), function($cells) {
$cells->setAlignment('right');
});
// 备注内容样式
$sheet->cells('E'.($tot-10).':F'.($tot-6), function($cells) {
$cells->setAlignment('left');
$cells->setFontColor('#a09b9b');
$cells->setFontFamily('Calibri');
$cells->setFontWeight('normal');
$cells->setFontSize(12);
});
// 总金额 高亮显示
$sheet->cells('F'.($tot-14), function($cells) {
$cells->setBackground('#87eabd');
$cells->setFontWeight('bold');
$cells->setFontSize(14);
});
});
})->export('xls');
}else{
$totalItems = $res->pagination->total;
$itemsPerPage = $res->pagination->per_page;
$currentPage = $res->pagination->current_page;
if ($http_build_query)
{
$urlPattern = url('finance/listing?'.$http_build_query.'&page=') . '(:num)';
}else{
$urlPattern = url('finance/listing') .'?page=(:num)';
}
$paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);
$paginator->setPreviousText('上一页');
$paginator->setNextText('下一页');
$data['listing'] = $res->results;
$data['paginator'] = $paginator;
$data['query'] = $query;
return view('financeRecords.listing', $data);
}
} else {
return redirect()
->back()
->withErrors($res->message)
->withInput();
}
上一篇: 构造与析构课上栗子1
下一篇: 架设laravel
推荐阅读
-
laravel框架设计excel表格式
-
用PHP将mysql数据表转换为excel文件格式_PHP教程
-
php的laravel框架解决视频上传和多种格式视频播放
-
如何将postgresql数据库表内数据导出为excel格式(推荐)
-
C#语言MVC框架Aspose.Cells控件导出Excel表数据
-
C#语言MVC框架Aspose.Cells控件导出Excel表数据
-
Solidworks工程图的明细表怎么导出为Excel格式?
-
在Excel 员工信息表中利用条件格式标注进行生日提醒以提前15天为例
-
PHP框架Laravel中使用UUID实现数据分表操作示例
-
EXCEL合并计算实现汇总分布在同样格式的各个工作表中的数据