PhpSpreadsheet导出图片

news/2024/11/21 21:18:21/

PhpSpreadsheet导出图片

php">    //导出public function pdf($ids){$jzInfo = $this->model->where('id',$ids)->find();try {//巡检人员$staff_ids = \app\admin\model\inspection\Plan::where('id',$jzInfo['plan_id'])->value('staff_id');$staff_names = \app\admin\model\inspection\Staff::whereIn('id',$staff_ids)->column('staff_name');$staff_names = implode(',',$staff_names);$salf_ids = \app\admin\model\inspection\Plan::where('id',$jzInfo['plan_id'])->value('salf_id');$salf_names = \app\admin\model\inspection\Staff::where('id',$salf_ids)->value('staff_name');$spreadsheet = new Spreadsheet();$worksheet = $spreadsheet->getActiveSheet();//设置工作表标题名称$worksheet->setTitle('电梯托管日常巡检');//表头//设置单元格内容setCellValueByColumnAndRow(列,行)$worksheet->setCellValueByColumnAndRow(1, 1, '海康智慧城市科技(广东)有限公司电梯托管日常巡检表');//合并单元格$worksheet->mergeCells('A1:B1');$worksheet->setCellValueByColumnAndRow(1, 5, '巡检内容');$worksheet->setCellValueByColumnAndRow(2, 5, ' 巡检结果');$styleBorderArray = ['borders' => ['outline' => ['borderStyle' => Border::BORDER_THIN, // 边框样式'color' => ['argb' => '0000000'], // 边框颜色],],];$styleArray = ['font' => ['bold' => true],'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,],'borders' => ['outline' => ['borderStyle' => Border::BORDER_THIN, // 边框样式'color' => ['argb' => '0000000'], // 边框颜色],],];//设置单元格样式$worksheet->getStyle('A1:B1')->applyFromArray($styleArray)->getFont()->setSize(16);$worksheet->getStyle('A5')->applyFromArray($styleBorderArray);$worksheet->getStyle('B5')->applyFromArray($styleBorderArray);$list = \app\admin\model\inspection\ProjectSite::alias("project_site")->field("project_site.*,inspection_area.area_name,inspection_area_site.site_name")->join("inspection_area","project_site.area_id=inspection_area.id")->join("inspection_area_site","project_site.area_site_id=inspection_area_site.id")->where('project_site.id',$ids)->select();$list_num = count($list);$change_num = 5+$list_num;$j = 6;for ($i=0; $i < $list_num; $i++) {//$j = $i + 4; //从表格第4行开始$val = $list[$i];$list_item = \app\admin\model\inspection\Projectitem::where('project_site_id','=',$val->id)->select();$item_count = count($list_item);if(empty($item_count)){continue;}//foreach($list_item as $v_item){$coummunit_id = $val['area_id'];for ($it=0; $it < $item_count; $it++) {$num = $j+$it;$worksheet->setCellValueByColumnAndRow(1, $num, $list_item[$it]['item_name']);$worksheet->setCellValueByColumnAndRow(2, $num, $list_item[$it]['value']==2?"正常":($list_item[$it]['value']==1?"异常":$list_item[$it]['value']));$worksheet->getStyle('A'.$num)->applyFromArray($styleBorderArray);$worksheet->getStyle('B'.$num)->applyFromArray($styleBorderArray);}$change_num +=$item_count;}$coumunity_name = \app\admin\model\Community::where('id',$list[0]['area_id'])->find();$worksheet->setCellValueByColumnAndRow(1, 2, "项目地点 : ".$coumunity_name['name']);$worksheet->mergeCells('A2:B2');$worksheet->getStyle('A2:B2')->applyFromArray($styleBorderArray);$worksheet->setCellValueByColumnAndRow(1, 3, '巡检时间 : '.date("Y-m-d H:i:s",$list[0]['checktime']));$worksheet->mergeCells('A3:B3');$worksheet->getStyle('A3:B3')->applyFromArray($styleBorderArray);$worksheet->setCellValueByColumnAndRow(1, 4, '设备注册代码 : '.$coumunity_name['device_code']);$worksheet->mergeCells('A4:B4');$worksheet->getStyle('A4:B4')->applyFromArray($styleBorderArray);$worksheet->getColumnDimension('A')->setWidth(60);$worksheet->getColumnDimension('B')->setWidth(20);$worksheet->setCellValueByColumnAndRow(1, $change_num, "安全管理员 : ".(isset($staff_names)? $staff_names:''));$worksheet->setCellValueByColumnAndRow(2, $change_num, "安全总监 : ".(isset($salf_names)? $salf_names:''));$worksheet->getStyle('A'.$change_num)->applyFromArray($styleBorderArray);$worksheet->getStyle('B'.$change_num)->applyFromArray($styleBorderArray);//清洁项目$worksheet->setCellValueByColumnAndRow(1, 96, '海康智慧城市科技(广东)有限公司电梯托管清洁记录表');$worksheet->getStyle('A96:B96')->applyFromArray($styleArray)->getFont()->setSize(16);//合并单元格$worksheet->mergeCells('A96:B96');$worksheet->getStyle('A2:B2')->applyFromArray($styleBorderArray);$worksheet->setCellValueByColumnAndRow(1, 97, "项目地点 : ".$coumunity_name['name']);$worksheet->mergeCells('A97:B97');$worksheet->getStyle('A97:B97')->applyFromArray($styleBorderArray);//$completetime = \app\admin\model\inspection\Project::where('id',$jzInfo['project_id'])->value('completetime');$worksheet->setCellValueByColumnAndRow(1, 98, '清洁时间 : '.date("Y-m-d H:i:s",$list[0]['checktime']));$worksheet->mergeCells('A98:B98');$worksheet->getStyle('A98:B98')->applyFromArray($styleBorderArray);$worksheet->setCellValueByColumnAndRow(1, 99, '设备注册代码 : '.$coumunity_name['device_code']);$worksheet->mergeCells('A99:B99');$worksheet->getStyle('A99:B99')->applyFromArray($styleBorderArray);$worksheet->setCellValueByColumnAndRow(1, 100, '清洁内容');$worksheet->setCellValueByColumnAndRow(2, 100, ' 清洁结果');$worksheet->getStyle('A100')->applyFromArray($styleBorderArray);$worksheet->getStyle('B100')->applyFromArray($styleBorderArray);$change_nums = 100+$list_num;$j = 101;for ($i=0; $i < $list_num; $i++) {//$j = $i + 4; //从表格第4行开始$val = $list[$i];$list_item = \app\admin\model\inspection\Projectclear::where('project_site_id','=',$val->id)->select();$item_count = count($list_item);if(empty($item_count)){continue;}$coummunit_id = $val['area_id'];for ($it=0; $it < $item_count; $it++) {$num = $j+$it;$worksheet->setCellValueByColumnAndRow(1, $num, $list_item[$it]['item_name']);$worksheet->setCellValueByColumnAndRow(2, $num, $list_item[$it]['value']==2?"正常":($list_item[$it]['value']==1?"异常":$list_item[$it]['value']));$worksheet->getStyle('A'.$num)->applyFromArray($styleBorderArray);$worksheet->getStyle('B'.$num)->applyFromArray($styleBorderArray);}$change_nums +=$item_count;}//盖章$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();$drawing->setPath("./excel/xun.png");$drawing->setWidth(80);$drawing->setCoordinates('B'.$change_num/2);$drawing->setWorksheet($worksheet);//七牛图片下载$config = get_addon_config('qiniu');$bucket = $config['bucket'];$auth = new Auth($config['accessKey'], $config['secretKey']);$images = explode(',',$jzInfo['images']);$change_num = $change_num +1;$worksheet->setCellValueByColumnAndRow(1, $change_num, '巡检图片');$worksheet->mergeCells('A'.$change_num.':B'.$change_num);$styleArray = ['font' => ['bold' => true],'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,],];$worksheet->getStyle('A'.$change_num.':B'.$change_num)->applyFromArray($styleArray)->getFont()->setSize(16);//巡检图片导出到excelforeach($images as $key => $imageUrl){++$change_num;$worksheet->getRowDimension($change_num)->setRowHeight(70);//合并单元格// $worksheet->mergeCells('A'.$change_num.':B'.$change_num);// $worksheet->setHeight(300);$imageSavePath = './excel/image'.$key.'.jpg';// 下载图片到本地$imageUrl = $auth->privateDownloadUrl($imageUrl);file_put_contents($imageSavePath, file_get_contents($imageUrl));$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();$drawing->setResizeProportional(false);$drawing->setPath($imageSavePath);$drawing->setHeight(70);$drawing->setWidth(60);// $drawing->setOffsetX(12);// $drawing->setOffsetY(12);$drawing->setCoordinates('A'.$change_num);$drawing->setWorksheet($worksheet);//$change_num += 40;// 最后删除本地图片//unlink($imageSavePath);}$filename = $coumunity_name['name'].'电梯托管日常巡检表.xlsx';header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');header('Content-Disposition: attachment;filename="'.$filename.'"');header('Cache-Control: max-age=0');// 保存Excel文件$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');$writer->save('php://output');} catch (Exception $e) {dump($e->getMessage());}}

http://www.ppmy.cn/news/1548858.html

相关文章

全网首发:Ubuntu编译跨平台嵌入式支持ffmpeg的OpenCV

难题&#xff1a; 使用cmake编译&#xff0c;死活找不到ffmpeg 使用cmake-gui&#xff0c;能找到ffmpeg&#xff0c;不能编译。 解决思路 结合cmake和cmake-gui。 为了给初次编译的朋友一点方便&#xff0c;这里专门完整详细记录。 安装编译环境 其他的略。 apt -y in…

QT使用libssh2库通过密匙实现sftp协议上传文件

1、先使用第三方库测试密匙连接,包括客户端和服务端安装,其中客户端使用的是winscp,服务器端使用的是freesshd,都安装在windows系统下,客户端和服务器端下载及安装配置以及libssh2通过用户名和密码连接可以参考上一篇文章:https://blog.csdn.net/u012372584/article/deta…

ISCTF 2024 web

ISCTF 2024 web 小蓝鲨的冒险 源码&#xff1a; <?php error_reporting(0); highlight_file(__FILE__); $a "isctf2024"; $b $_GET["b"]; parse_str($b); echo "小蓝鲨开始闯关&#xff0c;你能帮助他拿到flag吗?<br>"; if ($a…

【网页设计】HTML5 和 CSS3 提高

目标 能够说出 3~5 个 HTML5 新增布局和表单标签能够说出 CSS3 的新增特性有哪些 1. HTML5 的新特性 注&#xff1a;该部分所有内容可参考菜鸟教程菜鸟教程 - 学的不仅是技术&#xff0c;更是梦想&#xff01; (runoob.com) HTML5 的新增特性主要是针对于以前的不足&#xf…

【linux学习指南】VSCode部署Ubantu云服务器,与Xshell进行本地通信文件编写

文章目录 &#x1f4dd;前言&#x1f320; 步骤&#x1f309;测试同步 &#x1f6a9;总结 &#x1f4dd;前言 本文目的是讲使用Vscode连接Ubantu,与本地Xshell建立通信同步文件编写。 查看本机系统相关信息&#xff1a; cat /etc/lsb*DISTRIB_IDUbuntu: 表示这是 Ubuntu 发行…

如何在 Ubuntu 上安装 Mattermost 团队协作工具

简介 Mattermost 是一个开源、自托管的通信平台&#xff0c;专为团队协作设计。它类似于 Slack&#xff0c;提供聊天、消息传递和集成功能。Mattermost 在重视数据隐私的组织中特别受欢迎&#xff0c;因为它允许团队在自己的服务器上管理通信。以下是 Mattermost 的一些关键特…

解决Excel文件流读取数字为时间乱码问题

在将Excel文件流转换为Java中的List时&#xff0c;如果遇到文本被错误地识别为日期格式的问题&#xff0c;这通常是由于Apache POI库在处理单元格数据时默认的行为所导致的。Apache POI会尝试根据单元格的内容自动确定其类型&#xff0c;包括字符串、数字&#xff08;可能解释为…

【Linux】进程间通信——匿名管道

&#x1f525; 个人主页&#xff1a;大耳朵土土垚 &#x1f525; 所属专栏&#xff1a;Linux系统编程 这里将会不定期更新有关Linux的内容&#xff0c;欢迎大家点赞&#xff0c;收藏&#xff0c;评论&#x1f973;&#x1f973;&#x1f389;&#x1f389;&#x1f389; 文章目…