From fea8e0742ee241a94c5bbd4f452d6ad82cf4dd9c Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 06 二月 2026 10:58:26 +0800
Subject: [PATCH] 功能开发
---
server/services/src/main/java/com/doumee/core/annotation/excel/ExcelPictureUtil.java | 81 +++++++++++++++++++++++++++++++++++++---
1 files changed, 74 insertions(+), 7 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelPictureUtil.java b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelPictureUtil.java
index 4850f08..9d9ec0c 100644
--- a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelPictureUtil.java
+++ b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelPictureUtil.java
@@ -7,17 +7,13 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -315,4 +311,75 @@
}
}
+
+ /**
+ * 鑾峰彇鍗曞厓鏍间腑鐨勫浘鐗�
+ */
+
+ public static List<XSSFPictureData> getPicturesFromCell(Sheet sheet, Cell cell) {
+ try {
+ List<XSSFPictureData> cellPictures = new ArrayList<>();
+ XSSFDrawing drawing = ((XSSFSheet) sheet).createDrawingPatriarch();
+ if (drawing != null) {
+ List<XSSFPicture> pictures = drawing.getShapes().stream()
+ .filter(shape -> shape instanceof XSSFPicture)
+ .map(shape -> (XSSFPicture) shape).collect(Collectors.toList());
+ for (XSSFPicture picture : pictures) {
+ int rowIndex = picture.getPreferredSize().getRow1();
+ int colIndex = picture.getPreferredSize().getCol1();
+ if (colIndex == cell.getColumnIndex() && rowIndex == cell.getRowIndex()) {
+ cellPictures.add(picture.getPictureData());
+ }
+ }
+ }
+ return cellPictures;
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private static Map<String, List<XSSFPicture>> getImgPathMap(Sheet sheet) {
+ Map<String, List<XSSFPicture>> imgPathMap = new HashMap<>();
+ XSSFDrawing drawing = ((XSSFSheet) sheet).createDrawingPatriarch();
+ if (drawing != null) {
+ List<XSSFPicture> pictures = drawing.getShapes().stream()
+ .filter(shape -> shape instanceof XSSFPicture)
+ .map(shape -> (XSSFPicture) shape).collect(Collectors.toList());
+ for (XSSFPicture picture : pictures) {
+ int rowIndex = picture.getPreferredSize().getRow1();
+ int colIndex = picture.getPreferredSize().getCol1();
+ String key = colIndex + "-" + rowIndex;
+ List<XSSFPicture> list = null;
+ if (imgPathMap.containsKey(key)) {
+ list = imgPathMap.get(key);
+ } else {
+ list = new ArrayList<>();
+ imgPathMap.put(key, list);
+ }
+ list.add(picture);
+ }
+ }
+ return imgPathMap;
+ }
+
+
+ /**
+ * 鑾峰彇鍥剧墖鐨勬墿灞曞悕
+ */
+
+ private static String getImageExtension(PictureData picture) {
+ String mimeType = picture.getMimeType();
+ switch (mimeType) {
+ case "image/jpeg":
+ return "jpg";
+ case "image/png":
+ return "png";
+ default:
+ return "";
+ }
+ }
+
+
+
}
\ No newline at end of file
--
Gitblit v1.9.3