From 410874f2805b58c93dbf181d54e930283070c731 Mon Sep 17 00:00:00 2001 From: dlaren Date: Sun, 10 Aug 2025 11:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20?= =?UTF-8?q?=E5=9F=BA=E4=BA=8Exlsx4j=E7=AE=80=E5=8D=95=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AutoWps/vo/WpsXlsxInfoVo.java | 25 ++++++ .../wps_excel/JudgementWpsExcelService.java | 15 ++-- .../JudgementWpsExcelServiceImpl.java | 17 ++++ .../wps_excel/xlsx4j/XlsxConversion.java | 79 +++++++++++++++++ .../utils/wps_excel/xlsx4j/XlsxMaster.java | 85 +++++++++++++++++++ .../wps_excel/xlsx4j/vo/JudgementXlsxVO.java | 17 ++++ .../wps_excel/xlsx4j/vo/XlsxDataInfoVO.java | 19 +++++ .../utils/wps_pptx/pptx4j/SlideMaster.java | 2 - 8 files changed, 251 insertions(+), 8 deletions(-) create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/vo/WpsXlsxInfoVo.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxConversion.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxMaster.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/JudgementXlsxVO.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/XlsxDataInfoVO.java diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/vo/WpsXlsxInfoVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/vo/WpsXlsxInfoVo.java new file mode 100644 index 00000000..f560504a --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/vo/WpsXlsxInfoVo.java @@ -0,0 +1,25 @@ +package pc.exam.pp.module.judgement.controller.admin.AutoWps.vo; + +import lombok.Data; + +@Data +public class WpsXlsxInfoVo { + + // 大类名称 + private String firstName; + + // 序号 + private String index; + + // 方法名称 + private String function; + + // 考点名称 + private String examName; + + // 考点代码 + private String examCode; + + // 方式方法 + private String method; +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java index b15b2d59..ae985085 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java @@ -1,6 +1,13 @@ package pc.exam.pp.module.judgement.service.wps_excel; +import org.springframework.web.multipart.MultipartFile; +import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsXlsxInfoVo; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo.JudgementXlsxVO; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo.XlsxDataInfoVO; + +import java.util.List; + /** * 判分逻辑集合(wps excel) * @@ -8,11 +15,7 @@ package pc.exam.pp.module.judgement.service.wps_excel; */ public interface JudgementWpsExcelService { - /** - * 获取word文件内得考点及描述 - * @param path minio文件路径 - * @return 文件内得考点及描述 - * @throws Exception 异常 - */ + List xlsxMaster(List wpsXlsxInfoVos, MultipartFile file) throws Exception; + List xlsxDataInfo(MultipartFile file) throws Exception; } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java index 3344c2dd..704095ee 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java @@ -3,9 +3,26 @@ package pc.exam.pp.module.judgement.service.wps_excel; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsXlsxInfoVo; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.XlsxConversion; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.XlsxMaster; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo.JudgementXlsxVO; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo.XlsxDataInfoVO; + +import java.util.List; @Service public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { + @Override + public List xlsxMaster(List wpsXlsxInfoVos, MultipartFile file) throws Exception { + return XlsxMaster.xlsxMaster(wpsXlsxInfoVos, file); + } + + @Override + public List xlsxDataInfo(MultipartFile file) throws Exception { + return XlsxConversion.XlsxDataInfos(file); + } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxConversion.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxConversion.java new file mode 100644 index 00000000..844251ea --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxConversion.java @@ -0,0 +1,79 @@ +package pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j; + +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.xmlbeans.XmlCursor; +import org.springframework.web.multipart.MultipartFile; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo.XlsxDataInfoVO; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class XlsxConversion { + // 大纲 + // 1、获取第一层目录 幻灯片 - 母版 - 设置 - 其他 + // 2、获取第二层目录 第x页 - 幻灯片母版/备注母版 - 幻灯片设置 - 文件操作 + // 3、获取第三层目录 幻灯片设置/形状 - 幻灯片母版 - 幻灯片设置 - 文件操作 + public static List XlsxDataInfos(MultipartFile file) throws Exception { + List dataInfoVOS = new ArrayList<>(); + try (InputStream inputStream = file.getInputStream(); + OPCPackage pkg = OPCPackage.open(inputStream); + XSSFWorkbook workbook = new XSSFWorkbook(pkg)) { + // 获取有多少个工作表 + int sheetNumber = workbook.getNumberOfSheets(); + String firstId = getStringRandom(); + setXlsxDataInfo(firstId, "", "工作表", "sheet", "", false, dataInfoVOS); + for (int i = 0; i < sheetNumber; i++) { + // 获取工作表内容 + XSSFSheet sheetXss = workbook.getSheetAt(i); + String secondId = getStringRandom(); + setXlsxDataInfo(secondId, firstId, "sheet" + i + 1, "sheetInfo", "", true, dataInfoVOS); + String thirdId = getStringRandom(); + // 常用方法 + setXlsxDataInfo(thirdId, secondId, "单元格", "cell", "", true, dataInfoVOS); + setXlsxDataInfo(thirdId, secondId, "范围", "range", "", true, dataInfoVOS); + setXlsxDataInfo(thirdId, secondId, "行", "row", "", true, dataInfoVOS); + setXlsxDataInfo(thirdId, secondId, "列", "col", "", true, dataInfoVOS); + setXlsxDataInfo(thirdId, secondId, "页面", "page", "", true, dataInfoVOS); + setXlsxDataInfo(thirdId, secondId, "视图", "view", "", true, dataInfoVOS); + setXlsxDataInfo(thirdId, secondId, "属性", "style", "", true, dataInfoVOS); + // 剩余需要查询xml,特定文件存在才会显示 + } + + + } catch (Exception e) { + throw new RuntimeException(e); + } + return dataInfoVOS; + } + + public static String getStringRandom() { + String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + + // 生成指定长度的随机字符字符串 + for (int i = 0; i < 10; i++) { + int randomIndex = random.nextInt(characters.length()); + // 随机字符 + sb.append(characters.charAt(randomIndex)); + } + return sb.toString(); + } + + // 想数组中添加数据 + public static void setXlsxDataInfo(String id, String parentId, String text, + String type, String index, boolean isTrue, List dataInfoVOS) throws Exception { + XlsxDataInfoVO dataInfo = new XlsxDataInfoVO(); + dataInfo.setId(id); + dataInfo.setParentId(parentId); + dataInfo.setName(text); + dataInfo.setType(type); + dataInfo.setIndex(index); + dataInfo.setClick(isTrue); + dataInfoVOS.add(dataInfo); + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxMaster.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxMaster.java new file mode 100644 index 00000000..e6e73860 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/XlsxMaster.java @@ -0,0 +1,85 @@ +package pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j; + +import org.docx4j.openpackaging.exceptions.Docx4JException; +import org.docx4j.openpackaging.packages.OpcPackage; +import org.docx4j.openpackaging.packages.PresentationMLPackage; +import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; +import org.docx4j.openpackaging.parts.Part; +import org.docx4j.openpackaging.parts.PresentationML.SlidePart; +import org.docx4j.openpackaging.parts.SpreadsheetML.WorkbookPart; +import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; +import org.pptx4j.pml.GroupShape; +import org.pptx4j.pml.Shape; +import org.springframework.web.multipart.MultipartFile; +import org.xlsx4j.sml.*; +import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsXlsxInfoVo; +import pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo.JudgementXlsxVO; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +public class XlsxMaster { + + /** + * 读取Xlsx属性 + * @param wpsXlsxInfoVos 考点列表 + * @param file 文件 + * @return + * @throws IOException IO + * @throws Docx4JException 异常 + */ + public static List xlsxMaster(List wpsXlsxInfoVos, MultipartFile file) throws IOException, Docx4JException { + List judgementXlsxVOS = new ArrayList<>(); + // 1、获取想要判断的文件地址(文件流) + try (InputStream inputStream = file.getInputStream()) { + // 加载 .pptx 文件 + SpreadsheetMLPackage pkg = SpreadsheetMLPackage.load(inputStream); + WorkbookPart wb = pkg.getWorkbookPart(); + // 1) 先从 workbook 的 里拿到每个 sheet 的 r:id 和 name + List sheets = wb.getJaxbElement().getSheets().getSheet(); + for (Sheet s : sheets) { + String rId = s.getId(); // 关系ID + String sheetName = s.getName();// 工作表名称 + + // 2) 用 r:id 到关系表里取真正的 WorksheetPart + Part part = wb.getRelationshipsPart().getPart(rId); + WorksheetPart wsp = (WorksheetPart) part; + + System.out.println("=== Sheet: " + sheetName); + + // 3) 读行列 + for (Row row : wsp.getJaxbElement().getSheetData().getRow()) { + for (Cell c : row.getC()) { + System.out.print(readCellValue(c, wb) + "\t"); + } + System.out.println(); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return judgementXlsxVOS; + + } + // 读取单元格值(含共享字符串) + private static String readCellValue(Cell cell, WorkbookPart wb) { + if (cell.getT() == STCellType.S) { // 共享字符串 + if (wb.getSharedStrings() != null && cell.getV() != null) { + int idx = Integer.parseInt(cell.getV()); + // 兼容富文本:取第一个 + CTRst si = wb.getSharedStrings().getJaxbElement().getSi().get(idx); + if (si.getT() != null) return si.getT().getValue(); + if (!si.getR().isEmpty() && si.getR().get(0).getT() != null) + return si.getR().get(0).getT().getValue(); + } + return ""; + } + // 其他类型:直接返回底层值(数字/日期序列号/布尔等) + return cell.getV() == null ? "" : cell.getV(); + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/JudgementXlsxVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/JudgementXlsxVO.java new file mode 100644 index 00000000..d586aa44 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/JudgementXlsxVO.java @@ -0,0 +1,17 @@ +package pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo; + +import lombok.Data; + +/** + * @author REN + */ +@Data +public class JudgementXlsxVO { + + // 考点 + private String content; + + // 考点名称 + private String contentIn; + +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/XlsxDataInfoVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/XlsxDataInfoVO.java new file mode 100644 index 00000000..60b53be2 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/xlsx4j/vo/XlsxDataInfoVO.java @@ -0,0 +1,19 @@ +package pc.exam.pp.module.judgement.utils.wps_excel.xlsx4j.vo; + +import lombok.Data; + +@Data +public class XlsxDataInfoVO { + + private String name; + + private String type; + + private String id; + + private String parentId; + + private String index; + + private boolean isClick; +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java index ad97dc72..b1fcc123 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java @@ -1,12 +1,10 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j; -import org.docx4j.dml.chartDrawing.CTShape; import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.packages.OpcPackage; import org.docx4j.openpackaging.packages.PresentationMLPackage; import org.docx4j.openpackaging.parts.PresentationML.SlidePart; import org.pptx4j.pml.GroupShape; -import org.pptx4j.pml.Presentation; import org.pptx4j.pml.Shape; import org.springframework.web.multipart.MultipartFile; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;