作者 景龙
1 个管道 的构建 通过 耗费 6 秒

调试导出excel

... ... @@ -1454,7 +1454,7 @@ class CommonController extends RestBaseController
}
//根据项目id获取项目名称,甲方公司名称,logo,乙方公司名称,logo
public function getCompanyName($project_id){
public function getCompanyName($project_id,$report_name){
//获取甲方id,乙方id
$arr = [];
$project = $this->getProject(['id'=>$project_id],'id,a_cid,b_cid,name');
... ... @@ -1469,7 +1469,7 @@ class CommonController extends RestBaseController
$arr['b_company']['company_name'] = !empty($b_company['company_name'])?$b_company['company_name']:'';
$arr['b_company']['logo'] = !empty($b_company['logo'])?$host.'/upload/'.$b_company['logo']:'';
//报表标题
$arr['title'] = $project['name'].'报修表';
$arr['title'] = $project['name'].$report_name.'报表';
}
return $arr;
}
... ... @@ -1499,7 +1499,13 @@ class CommonController extends RestBaseController
//获取报修改造报表详情
public function getRepairReportDetail($res,$data,$flag){
$arr = [];
$company = $this->getCompanyName($res['project_id']);
if($flag == 'repair'){
//报修
$company = $this->getCompanyName($res['project_id'],'报修');
}else{
//改造
$company = $this->getCompanyName($res['project_id'],'改造');
}
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ... @@ -1637,7 +1643,14 @@ class CommonController extends RestBaseController
//获取培训演习报表详情
public function getTrainReportDetail($res,$data,$flag){
$arr = [];
$company = $this->getCompanyName($res['project_id']);
if($flag == 'train'){
//培训
$company = $this->getCompanyName($res['project_id'],'培训');
}else{
//演习
$company = $this->getCompanyName($res['project_id'],'演习');
}
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ... @@ -1759,7 +1772,7 @@ class CommonController extends RestBaseController
//获取月检报表详情
public function getCheckReportDetail($res,$data){
$arr = [];
$company = $this->getCompanyName($res['project_id']);
$company = $this->getCompanyName($res['project_id'],'月检');
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ... @@ -1850,7 +1863,13 @@ class CommonController extends RestBaseController
//获取日检年检报表详情
public function getInspectReportDetail($res,$data,$flag){
$arr = [];
$company = $this->getCompanyName($res['project_id']);
if($flag == 'inspect'){
//日检
$company = $this->getCompanyName($res['project_id'],'巡检/日检');
}else{
//年检
$company = $this->getCompanyName($res['project_id'],'年检');
}
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ...
... ... @@ -123,16 +123,16 @@ class AdminCheckController extends AdminBaseController
$arr['status'] = $this->getStatus()[$value['status']];
//获取文件路径
$url = $adminExcel->checkExcelData($arr);
//按日导出
$arr_url[$key] = $url;
$arr_time[$key] = $arr['time'].'报表.xls';
// //按日导出
// $arr_url[$key] = $url;
// $arr_time[$key] = $arr['time'].'报表.xls';
}
$xlsName = '月检报表';
//解决zip中文文件名
$xlsName = $adminCommon->iconv_to_utf8($xlsName);
$filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
$adminCommon->zip($arr_url,$filename,$arr_time);
// $xlsName = '月检报表';
// //解决zip中文文件名
// $xlsName = $adminCommon->iconv_to_utf8($xlsName);
// $filename = ROOT_PATH . 'public/upload/export/' . $xlsName . '.zip';
// $adminCommon->zip($arr_url,$filename,$arr_time);
}
//检查是否有数据
... ...
... ... @@ -379,7 +379,7 @@ class AdminCommonController extends AdminBaseController
}
//根据项目id获取项目名称,甲方公司名称,logo,乙方公司名称,logo
public function getCompanyName($project_id){
public function getCompanyName($project_id,$report_name){
//获取甲方id,乙方id
$arr = [];
$project = $this->getProject(['id'=>$project_id],'id,a_cid,b_cid,name');
... ... @@ -393,7 +393,7 @@ class AdminCommonController extends AdminBaseController
$arr['b_company']['company_name'] = !empty($b_company['company_name'])?$b_company['company_name']:'';
$arr['b_company']['logo'] = !empty($b_company['logo'])?'upload/'.$b_company['logo']:'';
//报表标题
$arr['title'] = $project['name'].'报修表';
$arr['title'] = $project['name'].$report_name.'报表';
}
return $arr;
}
... ... @@ -613,7 +613,7 @@ class AdminCommonController extends AdminBaseController
public function checkExportData($res){
$arr = [];
//甲乙方logo,名称,报表名称
$company = $this->getCompanyName($res['project_id']);
$company = $this->getCompanyName($res['project_id'],'月检');
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ...
... ... @@ -133,14 +133,20 @@ class AdminExcelDataController extends AdminBaseController
$sheet->setCellValue('G7', $arr['inspect_status']);
//循环开始
$cols = 10;
$cells = ['C','E','G','I','K'];
foreach($arr['point'] as $value){
$cols += 0;
//巡检点名称
$sheet->setCellValue('B'.$cols, $value['point_name']);
$sheet->getStyle('B'.$cols)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
$array = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->mergeCells('A'.$cols.':B'.$cols);
$sheet->setCellValue('A'.$cols, $value['point_name']);
$sheet->getStyle('A'.$cols)->getAlignment()->applyFromArray($array);//垂直水平居中
//获取图片个数
$length = count($value['images']);
$col = ceil($length/5);
... ... @@ -294,16 +300,41 @@ class AdminExcelDataController extends AdminBaseController
$sheet->setTitle($xlsName.$name);
//合并单元格
//报表名称
$sheet->mergeCells('B1:J1');
//甲方logo,甲方公司名称
$sheet->mergeCells('B3:B4');
$sheet->mergeCells('B6:D6');
$sheet->mergeCells('B7:D7');
$sheet->mergeCells('C3:D3');
$sheet->mergeCells('C4:D4');
//乙方logo,乙方公司名称
$sheet->mergeCells('F3:F4');
$sheet->mergeCells('G3:I3');
$sheet->mergeCells('G4:I4');
//乙方发起人姓名
$sheet->mergeCells('B6:C6');
$sheet->mergeCells('B7:C7');
//乙方项目组
$sheet->mergeCells('F6:H6');
$sheet->mergeCells('F7:H7');
//月检状态
$sheet->mergeCells('I6:J6');
$sheet->mergeCells('I7:J7');
//甲方领导确认人
$sheet->mergeCells('B9:C9');
$sheet->mergeCells('B10:C10');
//乙方员工确认人
$sheet->mergeCells('D9:E9');
$sheet->mergeCells('D10:E10');
$spreadsheet->getDefaultStyle()->getFont()->setName('微软雅黑');//字体
//设置默认宽
... ... @@ -313,8 +344,8 @@ class AdminExcelDataController extends AdminBaseController
// $sheet->getRowDimension(2)->setRowHeight(55);
//***********************背景填充颜色*****************************
$sheet->getStyle( 'A1:M8')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A1:M8')->getFill()->getStartColor()->setRGB('222B35');//背景颜色
$sheet->getStyle( 'A1:M11')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A1:M11')->getFill()->getStartColor()->setRGB('222B35');//背景颜色
//***********************画出单元格边框结束*****************************
//标题
... ... @@ -337,11 +368,13 @@ class AdminExcelDataController extends AdminBaseController
$imageADrawing->setWorksheet($sheet);
}
$sheet->getStyle('B3:G7')->getFont()->setSize(8);//字体大小
$sheet->getStyle('B3:J10')->getFont()->setSize(8);//字体大小
$sheet->getStyle('C3:G3')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('B6:G6')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('B6:I6')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('B9:I9')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
$sheet->getStyle('C4:G4')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B7:G7')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B7:I7')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
$sheet->getStyle('B10:I10')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
//甲方公司
$sheet->setCellValue('C3', '甲方公司');
... ... @@ -367,30 +400,101 @@ class AdminExcelDataController extends AdminBaseController
//乙方公司名称
$sheet->setCellValue('G4', $arr['b_company']['company_name']);
//项目组
$sheet->setCellValue('B6', '项目组');
//项目组名称
$sheet->setCellValue('B7', $arr['group_name']);
//乙方发起人姓名
$sheet->setCellValue('B6', '乙方发起人');
$sheet->setCellValue('B7', '景龙');
//巡检日期
$sheet->setCellValue('E6', '巡检日期');
//巡检日期名称
$sheet->setCellValue('E7', $arr['create_time']);
//月检时间
$sheet->setCellValue('D6', '月检时间');
$sheet->setCellValue('D7', '2019/06/30');
//巡检状态
$sheet->setCellValue('G6', '巡检状态');
//巡检状态名称
$sheet->setCellValue('G7', $arr['inspect_status']);
//乙方项目组
$sheet->setCellValue('F6', '项目组');
$sheet->setCellValue('F7', '景龙、员工2、尚光泉');
//循环开始
//月检状态
$sheet->setCellValue('I6', '月检状态');
$sheet->setCellValue('I7', '待乙方员工完成');
$cols = 10;
//甲方领导确认人
$sheet->setCellValue('B9', '甲方领导确认人');
$sheet->setCellValue('B10', '景龙');
//乙方员工确认人
$sheet->setCellValue('D9', '乙方员工确认人');
$sheet->setCellValue('D10', '景龙');
//完成时间
$sheet->setCellValue('F9', '完成时间');
$sheet->setCellValue('F10', '2019/06/30');
//工期
$sheet->setCellValue('I9', '工期');
$sheet->setCellValue('I10', '15天');
//循环开始
$cols = 13;
$cells = ['C','E','G','I','K'];
$arr['point'] = [
[
'check_name'=>'月检图片',
'images'=>[
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
]
],
[
'check_name'=>'确认完成图片',
'images'=>[
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
['image_url'=>'upload/portal/20190525/659dbc14246df952abf4940e66dc89a0.jpg'],
]
]
];
foreach($arr['point'] as $value){
$cols += 0;
//巡检点名称
$sheet->setCellValue('B'.$cols, $value['point_name']);
$sheet->getStyle('B'.$cols)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
$array = [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
'textRotation' => 0,
'wrapText' => TRUE
];
$sheet->mergeCells('A'.$cols.':B'.$cols);
$sheet->setCellValue('A'.$cols, $value['check_name']);
$sheet->getStyle('A'.$cols)->getAlignment()->applyFromArray($array);//垂直水平居中
//获取图片个数
$length = count($value['images']);
$col = ceil($length/5);
... ... @@ -427,17 +531,16 @@ class AdminExcelDataController extends AdminBaseController
$cols += $col+1;
}
$sheet->getStyle( 'A9:M'.$cols)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A9:M'.$cols)->getFill()->getStartColor()->setRGB('F3F3F4');//背景颜色浅灰色
$sheet->getStyle( 'A12:M'.$cols)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$sheet->getStyle( 'A12:M'.$cols)->getFill()->getStartColor()->setRGB('F3F3F4');//背景颜色浅灰色
$objWrite = IOFactory::createWriter($spreadsheet, 'Xls');
//直接从浏览器中输出star
// header('pragma:public');
// header("Content-Disposition:attachment;filename=出货装箱单.xls");
// $objWrite->save('php://output');
// exit;
header('pragma:public');
header("Content-Disposition:attachment;filename=出货装箱单.xls");
$objWrite->save('php://output');
exit;
//直接从浏览器中输出end
$file_name = $xlsName.'.xls';
... ...
... ... @@ -193,7 +193,7 @@ class AdminInspectAController extends AdminBaseController
foreach($res_ins as $key=>$value){
$arr = [];
//甲乙方logo,名称,报表名称
$company = $adminCommon->getCompanyName($value['project_id']);
$company = $adminCommon->getCompanyName($value['project_id'],'巡检');
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ...
... ... @@ -138,7 +138,7 @@ class AdminInspectBController extends AdminBaseController
foreach($res_ins as $key=>$value){
$arr = [];
//甲乙方logo,名称,报表名称
$company = $adminCommon->getCompanyName($value['project_id']);
$company = $adminCommon->getCompanyName($value['project_id'],'日检');
if($company){
$arr['a_company'] = $company['a_company'];
$arr['b_company'] = $company['b_company'];
... ...