|
|
@@ -1,9 +1,12 @@
|
|
|
package cn.iocoder.yudao.module.pms.util;
|
|
|
|
|
|
+import org.apache.poi.util.Units;
|
|
|
import org.apache.poi.xwpf.usermodel.*;
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigInteger;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -13,15 +16,20 @@ public class SafetyObservationCardGenerator {
|
|
|
try (XWPFDocument document = new XWPFDocument();
|
|
|
FileOutputStream out = new FileOutputStream("行为安全观察与沟通卡-数智化.docx")) {
|
|
|
|
|
|
- // 1. 标题:科瑞石油技术
|
|
|
+ // 1. 标题:替换为KERUI科瑞石油技术图片(核心修改)
|
|
|
XWPFParagraph logoPara = document.createParagraph();
|
|
|
- logoPara.setAlignment(ParagraphAlignment.CENTER);
|
|
|
+ logoPara.setAlignment(ParagraphAlignment.CENTER); // 图片居中
|
|
|
XWPFRun logoRun = logoPara.createRun();
|
|
|
- logoRun.setText("KERUI科瑞石油技术");
|
|
|
- logoRun.setBold(true);
|
|
|
- logoRun.setFontSize(20);
|
|
|
- logoRun.setFontFamily("Arial");
|
|
|
- logoRun.setColor("0047AB");
|
|
|
+
|
|
|
+ // 读取本地图片并插入(替换为你的图片实际路径)
|
|
|
+ String imagePath = "pic/keruishiyoujishu.png";
|
|
|
+// 获取resources下图片的输入流(无需关心物理路径)
|
|
|
+ InputStream imageStream = new ClassPathResource(imagePath).getInputStream();
|
|
|
+
|
|
|
+// 然后将imageStream传入插入图片的方法(替代原有的FileInputStream)
|
|
|
+ XWPFRun run = logoPara.createRun();
|
|
|
+ run.addPicture(imageStream, XWPFDocument.PICTURE_TYPE_PNG, "keruishiyoujishu.png",
|
|
|
+ Units.toEMU(250), Units.toEMU(30)); // 宽高按需调整
|
|
|
|
|
|
document.createParagraph();
|
|
|
|
|
|
@@ -86,7 +94,7 @@ public class SafetyObservationCardGenerator {
|
|
|
// 行6:规范指挥明细 | 人员位置明细 | 安全行为描述(后续垂直合并)
|
|
|
XWPFTableRow row6 = table.createRow();
|
|
|
// ========== 核心修改1:设置row6行高(增高,示例:800缇 ≈ 40磅) ==========
|
|
|
- setRowHeight(row6, 1600);
|
|
|
+ setRowHeight(row6, 1900);
|
|
|
String cmdText = "";
|
|
|
String posText = "";
|
|
|
String safeText = "";
|
|
|
@@ -113,11 +121,13 @@ public class SafetyObservationCardGenerator {
|
|
|
|
|
|
// 行8:作业场所明细 | 空 | 不安全行为描述(后续垂直合并)
|
|
|
XWPFTableRow row8 = table.createRow();
|
|
|
- mergeCellsHorizontally(row8, 0, 1);
|
|
|
- String houseText = "□ 作业场所杂乱 □ 带电装置带电部分裸露\n□ 作业空间狭小 □ 设备无防护/防护装置不当\n□ 堵塞安全通道 □ 未工完料净场地清/垃圾未分类存放\n□ 地面滑(水/雨/雪/油污等) □ 通风不良/氧气含量未达标\n□ 物体/工具放置位置不当 □ 其他 _______________\n□ 危险场所没有标志/标志不清\n□ 照明光线不良";
|
|
|
+// mergeCellsHorizontally(row8, 0, 1);
|
|
|
+ String houseText = "□ 作业场所杂乱\n□ 作业空间狭小\n□ 堵塞安全通道\n□ 地面滑(水/雨/雪/油污等)\n□ 物体/工具放置位置不当 \n□ 危险场所没有标志/标志不清\n□ 照明光线不良";
|
|
|
+ String secondText = "□ 带电装置带电部分裸露\n□ 设备无防护/防护装置不当\n□ 未工完料净场地清/垃圾未分类存放\n□ 通风不良/氧气含量未达标\n□ 其他 _______________";
|
|
|
String unsafeText = "";
|
|
|
setCellStyle(row8.getCell(0), houseText, false, ParagraphAlignment.LEFT, "FFFFFF");
|
|
|
- setCellStyle(row8.getCell(2), unsafeText, false, ParagraphAlignment.LEFT, "E6EBF5");
|
|
|
+ setCellStyle(row8.getCell(1), secondText, false, ParagraphAlignment.LEFT, "FFFFFF");
|
|
|
+ setCellStyle(row8.getCell(2), unsafeText, false, ParagraphAlignment.LEFT, "FFFFFF");
|
|
|
|
|
|
// 底部信息行
|
|
|
XWPFTableRow footerRow = table.createRow();
|
|
|
@@ -164,7 +174,7 @@ public class SafetyObservationCardGenerator {
|
|
|
setCellBorder(cell);
|
|
|
}
|
|
|
|
|
|
- // 新增:提示文字专属样式设置
|
|
|
+ // 新增:提示文字专属样式设置(增加左缩进+行间距)
|
|
|
private static void setTipTextStyle(XWPFTableCell cell, String text, boolean bold, ParagraphAlignment align, String bgColor) {
|
|
|
clearCellContent(cell);
|
|
|
|
|
|
@@ -175,22 +185,24 @@ public class SafetyObservationCardGenerator {
|
|
|
|
|
|
XWPFParagraph paragraph = cell.addParagraph();
|
|
|
paragraph.setAlignment(align);
|
|
|
- paragraph.setSpacingAfter(0);
|
|
|
- paragraph.setSpacingBefore(0);
|
|
|
+ paragraph.setSpacingAfter(100); // 段后间距(缇,1磅=20缇)
|
|
|
+ paragraph.setSpacingBefore(100); // 段前间距
|
|
|
+ // 设置左缩进(示例:2字符缩进,1字符≈1440缇)
|
|
|
+ paragraph.setIndentationFirstLine(288);
|
|
|
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
run.setText(text.trim());
|
|
|
- run.setFontSize(9); // 设置字体大小为11号
|
|
|
- run.setFontFamily("宋体"); // 设置字体为微软雅黑
|
|
|
+ run.setFontSize(9); // 设置字体大小为9号
|
|
|
+ run.setFontFamily("宋体"); // 设置字体为宋体
|
|
|
run.setBold(true); // 加粗
|
|
|
- run.setColor("003366"); // 设置字体颜色为深蓝色(可自行修改)
|
|
|
- run.setTextPosition(10); // 调整文字间距
|
|
|
+ run.setColor("003366"); // 设置字体颜色为深蓝色
|
|
|
+ run.setTextPosition(10); // 行内文字垂直间距
|
|
|
|
|
|
cell.setColor(bgColor);
|
|
|
setCellBorder(cell);
|
|
|
}
|
|
|
|
|
|
- // 单元格样式设置(支持换行)
|
|
|
+ // 单元格样式设置(支持换行,增加左缩进+行间距)
|
|
|
private static void setCellStyle(XWPFTableCell cell, String text, boolean bold, ParagraphAlignment align, String bgColor) {
|
|
|
clearCellContent(cell);
|
|
|
|
|
|
@@ -201,18 +213,29 @@ public class SafetyObservationCardGenerator {
|
|
|
|
|
|
// 按换行符分割,每行创建一个新段落
|
|
|
String[] lines = text.split("\n");
|
|
|
- for (String line : lines) {
|
|
|
+ for (int i = 0; i < lines.length; i++) {
|
|
|
+ String line = lines[i];
|
|
|
XWPFParagraph paragraph = cell.addParagraph();
|
|
|
paragraph.setAlignment(align);
|
|
|
- paragraph.setSpacingAfter(0);
|
|
|
+ paragraph.setSpacingAfter(50); // 段后间距(每行之间的间距)
|
|
|
paragraph.setSpacingBefore(0);
|
|
|
|
|
|
+ // 关键:给包含□的行增加左缩进(2字符),普通行按需调整
|
|
|
+ if (line.startsWith("□")) {
|
|
|
+ // 1字符≈1440缇,2字符=2880缇,可根据需要调整
|
|
|
+ paragraph.setIndentationFirstLine(288);
|
|
|
+ } else {
|
|
|
+ // 非选择框行,缩进1字符
|
|
|
+ paragraph.setIndentationFirstLine(144);
|
|
|
+ }
|
|
|
+
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
run.setText(line.trim());
|
|
|
run.setFontSize(9);
|
|
|
run.setFontFamily("宋体");
|
|
|
run.setBold(bold);
|
|
|
- run.setTextPosition(0);
|
|
|
+ // 行内文字垂直间距(上下间距)
|
|
|
+ run.setTextPosition(12);
|
|
|
}
|
|
|
|
|
|
// 处理空文本
|