...
|
...
|
@@ -529,6 +529,183 @@ class AdminExcelDataController extends AdminBaseController |
|
|
return $url;
|
|
|
}
|
|
|
|
|
|
//年检渲染数据到表格上
|
|
|
public function testExcelData($arr){
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
$adminCommon = new AdminCommonController();
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
$xlsName = $arr['time'];
|
|
|
//设置sheet名称
|
|
|
$name = '报表';
|
|
|
$name = $adminCommon->iconv_to_utf8($name);
|
|
|
|
|
|
$sheet->setTitle($xlsName.$name);
|
|
|
//合并单元格
|
|
|
$sheet->mergeCells('B1:J1');
|
|
|
$sheet->mergeCells('B3:B4');
|
|
|
$sheet->mergeCells('B6:D6');
|
|
|
$sheet->mergeCells('B7:D7');
|
|
|
$sheet->mergeCells('C3:D3');
|
|
|
$sheet->mergeCells('C4:D4');
|
|
|
$sheet->mergeCells('F3:F4');
|
|
|
$sheet->mergeCells('G3:I3');
|
|
|
$sheet->mergeCells('G4:I4');
|
|
|
|
|
|
$spreadsheet->getDefaultStyle()->getFont()->setName('微软雅黑');//字体
|
|
|
|
|
|
//设置默认宽
|
|
|
$sheet->getDefaultColumnDimension()->setWidth(8);
|
|
|
//设置高度
|
|
|
$sheet->getRowDimension(1)->setRowHeight(45);
|
|
|
|
|
|
//***********************背景填充颜色*****************************
|
|
|
$sheet->getStyle( 'A1:M8')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
|
|
|
$sheet->getStyle( 'A1:M8')->getFill()->getStartColor()->setRGB('222B35');//背景颜色
|
|
|
//***********************画出单元格边框结束*****************************
|
|
|
|
|
|
//标题
|
|
|
$sheet->setCellValue('B1', $arr['title']);
|
|
|
$sheet->getStyle('B1')->getFont()->setSize(18);//字体大小
|
|
|
$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
|
|
|
$sheet->getStyle('B1')->getFont()->setBold(true);//字体加粗
|
|
|
|
|
|
//甲方logo
|
|
|
$imageA = $arr['a_company']['logo'];
|
|
|
if(@fopen($imageA , 'r' ) ) {
|
|
|
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
|
|
|
$imageADrawing = new Drawing();
|
|
|
$imageADrawing->setPath($imageA);
|
|
|
// 设置图片的宽度
|
|
|
$imageADrawing->setResizeProportional(false);
|
|
|
$imageADrawing->setWidthAndHeight(40,40);
|
|
|
//图片显示在B3
|
|
|
$imageADrawing->setCoordinates('B3');
|
|
|
$imageADrawing->setWorksheet($sheet);
|
|
|
}
|
|
|
|
|
|
$sheet->getStyle('B3:G7')->getFont()->setSize(8);//字体大小
|
|
|
$sheet->getStyle('C3:G3')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
|
|
|
$sheet->getStyle('B6:G6')->getFont()->getColor()->setRGB('949494');//设置颜色为灰色
|
|
|
$sheet->getStyle('C4:G4')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
|
|
|
$sheet->getStyle('B7:G7')->getFont()->getColor()->setRGB('FFFFFF');//设置颜色为白色
|
|
|
|
|
|
//甲方公司
|
|
|
$sheet->setCellValue('C3', '甲方公司');
|
|
|
//甲方公司名称
|
|
|
$sheet->setCellValue('C4', $arr['a_company']['company_name']);
|
|
|
|
|
|
//乙方logo
|
|
|
$imageB = $arr['b_company']['logo'];
|
|
|
if(@fopen($imageB , 'r' ) ) {
|
|
|
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
|
|
|
$objDrawing = new Drawing();
|
|
|
$objDrawing->setPath($imageB);
|
|
|
// 设置图片的宽度
|
|
|
$objDrawing->setResizeProportional(false);
|
|
|
$objDrawing->setWidthAndHeight(40,40);
|
|
|
//图片显示在F3
|
|
|
$objDrawing->setCoordinates('F3');
|
|
|
$objDrawing->setWorksheet($sheet);
|
|
|
}
|
|
|
|
|
|
//乙方公司
|
|
|
$sheet->setCellValue('G3', '乙方公司');
|
|
|
//乙方公司名称
|
|
|
$sheet->setCellValue('G4', $arr['b_company']['company_name']);
|
|
|
|
|
|
//项目组
|
|
|
$sheet->setCellValue('B6', '项目组');
|
|
|
//项目组名称
|
|
|
$sheet->setCellValue('B7', $arr['group_name']);
|
|
|
|
|
|
//巡检日期
|
|
|
$sheet->setCellValue('E6', '年检日期');
|
|
|
//巡检日期名称
|
|
|
$sheet->setCellValue('E7', $arr['test_time']);
|
|
|
|
|
|
|
|
|
//循环开始
|
|
|
$cols = 10;
|
|
|
$cells = ['C','E','G','I','K'];
|
|
|
foreach($arr['years'] as $value){
|
|
|
$cols += 0;
|
|
|
//巡检点名称
|
|
|
$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['spot_name']);
|
|
|
$sheet->getStyle('A'.$cols)->getAlignment()->applyFromArray($array);//垂直水平居中
|
|
|
//获取图片个数
|
|
|
$length = count($value['images']);
|
|
|
$col = ceil($length/5);
|
|
|
for($i=0;$i<$col;$i++){
|
|
|
$col_i = $cols+$i;
|
|
|
$sheet->getRowDimension($col_i)->setRowHeight(105);
|
|
|
$sheet->mergeCells('C'.$col_i.':D'.$col_i);
|
|
|
$sheet->mergeCells('E'.$col_i.':F'.$col_i);
|
|
|
$sheet->mergeCells('G'.$col_i.':H'.$col_i);
|
|
|
$sheet->mergeCells('I'.$col_i.':J'.$col_i);
|
|
|
$sheet->mergeCells('K'.$col_i.':L'.$col_i);
|
|
|
$key = 0;
|
|
|
foreach($value['images'] as $k=>$image_value){
|
|
|
$pre = $i+4*$i;
|
|
|
$next = $i+1+4*($i+1);
|
|
|
if($k>=$pre && $k<$next){
|
|
|
//巡检图片
|
|
|
$image = $image_value['image_url'];
|
|
|
if(@fopen($image , 'r' ) ) {
|
|
|
//这是一个坑,刚开始我把实例化图片类放在了循环外面,但是失败了,也就是每个图片都要实例化一次
|
|
|
$obj = new Drawing();
|
|
|
$obj->setPath($image);
|
|
|
// 设置图片的宽度
|
|
|
$obj->setResizeProportional(false);
|
|
|
$obj->setWidthAndHeight(105,130);
|
|
|
//图片显示在F3
|
|
|
$obj->setCoordinates($cells[$key].$col_i);
|
|
|
$obj->setWorksheet($sheet);
|
|
|
}
|
|
|
$key++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$cols += $col+1;
|
|
|
}
|
|
|
$sheet->getStyle( 'A9:M'.$cols)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID);
|
|
|
$sheet->getStyle( 'A9: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;
|
|
|
//直接从浏览器中输出end
|
|
|
|
|
|
$file_name = $xlsName.'.xls';
|
|
|
|
|
|
$files_url = ROOT_PATH . '/public/upload/export';
|
|
|
if(!is_dir($files_url)){
|
|
|
mkdir($files_url);
|
|
|
}
|
|
|
$file_url = ROOT_PATH . '/public/upload/export/'.$file_name;
|
|
|
$objWrite->save($file_url);
|
|
|
|
|
|
$sys = $adminCommon->getOperateSys();
|
|
|
if($sys == 'Linux'){
|
|
|
chmod($file_url, 0777);//适用于linux
|
|
|
}
|
|
|
//相对路径
|
|
|
$url = 'upload/export/'.$file_name;
|
|
|
return $url;
|
|
|
}
|
|
|
|
|
|
//培训演习渲染数据到表格上
|
|
|
public function trainExcelData($arr,$table){
|
|
|
$spreadsheet = new Spreadsheet();
|
...
|
...
|
|