From c72c95f66a00d04dd54e2b49a4f3e3766f01871f Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 09 一月 2026 15:28:22 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/utils/MapExcelUtils.java | 87 ++-----------------------------------------
1 files changed, 4 insertions(+), 83 deletions(-)
diff --git a/src/main/java/com/zy/asrs/utils/MapExcelUtils.java b/src/main/java/com/zy/asrs/utils/MapExcelUtils.java
index 7048859..bc28622 100644
--- a/src/main/java/com/zy/asrs/utils/MapExcelUtils.java
+++ b/src/main/java/com/zy/asrs/utils/MapExcelUtils.java
@@ -9,7 +9,6 @@
import com.zy.common.model.MapNode;
import com.zy.core.enums.MapNodeType;
import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;
@@ -258,74 +257,12 @@
String levStr = split[0];
Integer lev = Integer.parseInt(levStr);
- int idx = 0;
- int rowLength = -1;
- int cellLength = -1;
-
- Row titleRow = sheet.getRow(1);
- for (Cell cell : titleRow) {
- if (idx < 2) {
- idx++;
- continue;
- }
- HashMap<String, Object> map = getCellValue(sheet, titleRow, cell);
- String value = map.get("value").toString();
- if (!Cools.isEmpty(value)) {
- rowLength = (int) Double.parseDouble(value);
- }
- }
-
- idx = 0;
for (Row row : sheet) {
- if (idx < 2) {
- idx++;
- continue;
- }
-
- Cell cell = row.getCell(1);
- if(cell != null) {
- HashMap<String, Object> map = getCellValue(sheet, row, cell);
- String value = map.get("value").toString();
- if (!Cools.isEmpty(value)) {
- cellLength = (int) Double.parseDouble(value);
- }
- }
- }
-
- for (int j = 0; j < cellLength; j++) {
- Row row = sheet.getRow(j + 2);
List<HashMap<String, Object>> rowData = new ArrayList<>();
- for (int k = 0; k < rowLength; k++) {
- Cell cell = row.getCell(k + 2);
- rowData.add(getCellValue(sheet, row, cell));
+ for (Cell cell : row) {
+ rowData.add(getCellValue(cell));
}
data.add(rowData);
- }
-
- int numMergedRegions = sheet.getNumMergedRegions();
- for (int j = 0; j < numMergedRegions; j++) {
- CellRangeAddress region = sheet.getMergedRegion(j);
-
- int rowSpan = region.getLastRow() - region.getFirstRow() + 1;
- int colSpan = region.getLastColumn() - region.getFirstColumn() + 1;
-
- int rowIdx = region.getFirstRow() - 2;
- int colIdx = region.getFirstColumn() - 2;
- HashMap<String, Object> map = data.get(rowIdx).get(colIdx);
- map.put("rowSpan", rowSpan);
- map.put("colSpan", colSpan);
-
- for (int k = region.getFirstRow(); k <= region.getLastRow(); k++) {
- for (int l = region.getFirstColumn(); l <= region.getLastColumn(); l++) {
- if(k == region.getFirstRow() && l == region.getFirstColumn()) {
- continue;
- }
-
- HashMap<String, Object> mapData = data.get(k - 2).get(l - 2);
- mapData.put("bgColor", "merge");
- }
- }
-
}
dataMap.put(lev, data);
@@ -337,29 +274,15 @@
return dataMap;
}
- private HashMap<String, Object> getCellValue(Sheet sheet, Row row, Cell cell) {
+ private HashMap<String, Object> getCellValue(Cell cell) {
if (cell == null) {
- HashMap<String, Object> map = new HashMap<>();
- map.put("bgColor", "none");
- map.put("cellWidth", "");
- map.put("cellHeight", "");
- map.put("value", "");
- map.put("rowSpan", 1);
- map.put("colSpan", 1);
- return map;
+ return null;
}
HashMap<String, Object> map = new HashMap<>();
String bgColor = getCellBackgroundColor(cell);
map.put("bgColor", bgColor);
-
- int columnIndex = cell.getColumnIndex();
- int columnWidth = sheet.getColumnWidth(columnIndex);//鑾峰彇鍒楀
-
- short rowHeight = row.getHeight(); //鑾峰彇琛岄珮
- map.put("cellWidth", columnWidth);
- map.put("cellHeight", rowHeight);
String value = "";
switch (cell.getCellType()) {
@@ -388,8 +311,6 @@
}
map.put("value", value);
- map.put("rowSpan", 1);
- map.put("colSpan", 1);
return map;
}
--
Gitblit v1.9.1