From 68b27795ae929f5300fc6fb301b31aada74a2e2f Mon Sep 17 00:00:00 2001
From: zhangback <zhangback@163.com>
Date: 星期二, 10 三月 2026 15:26:03 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/yagwly_fa_master' into yagwly_fa_master

---
 common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
index 4c30fad..db83498 100644
--- a/common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+++ b/common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -4,7 +4,6 @@
 import com.ruoyi.common.annotation.Excel.ColumnType;
 import com.ruoyi.common.annotation.Excels;
 import com.ruoyi.common.config.RuoYiConfig;
-import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.UtilException;
 import com.ruoyi.common.utils.*;
@@ -18,6 +17,7 @@
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
 import org.apache.poi.xssf.usermodel.XSSFDataValidation;
@@ -39,7 +39,6 @@
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Predicate;
-import java.util.stream.Collectors;
 
 /**
  * Excel 澶勭悊宸ュ叿绫� - 鏀寔鍒嗛〉瀵煎嚭鍜屽ぇ鎵归噺鏁版嵁澶勭悊
@@ -58,7 +57,7 @@
     private static final String DEFAULT_FONT = "Arial" ; // 榛樿瀛椾綋
 
     // 鏍稿績灞炴��
-    private final Class<T> clazz; // 瀹炰綋绫荤被鍨�
+    private Class<T> clazz; // 瀹炰綋绫荤被鍨�
     private SXSSFWorkbook workbook; // Excel 宸ヤ綔绨垮璞�
     private Workbook wb; // Excel 宸ヤ綔绨垮璞�
     private Sheet currentSheet; // 褰撳墠宸ヤ綔琛�
@@ -257,6 +256,32 @@
             if (hasSubList()) createSubHeader();
             writeHeaderRow();
         }
+    }
+    public ExcelUtil switchSheet(int index, String name, Class clazz){
+        sheetIndex = index;
+        sheetName = name;
+        this.clazz = Objects.requireNonNull(clazz, "Class type cannot be null");
+
+        SXSSFSheet sheetAt = null;
+        // 妫�鏌ョ储寮曟槸鍚﹀湪鏈夋晥鑼冨洿鍐�
+        if (index >= 0 && index < workbook.getNumberOfSheets()) {
+            try {
+                sheetAt = workbook.getSheetAt(index);
+            } catch (IllegalArgumentException e) {
+                // 濡傛灉浠嶇劧鏈夐棶棰橈紝璺宠繃骞跺垱寤烘柊鐨�
+            }
+        }
+        if (sheetAt == null){
+            initializeFields();
+            currentSheet = workbook.createSheet(sheetName);
+            currentRowNum.set(0);
+            createTitleRow();
+            if (hasSubList()) createSubHeader();
+            writeHeaderRow();
+        }else{
+            currentSheet  = sheetAt;
+        }
+        return this;
     }
 
     /**
@@ -1045,7 +1070,8 @@
      */
     private String getDictLabel(String value, String dictType, String separator) {
         String key = dictType + value;
-        return dictCache.computeIfAbsent(key, k -> DictUtils.getDictLabel(dictType, value, separator));
+        String s = dictCache.computeIfAbsent(key, k -> DictUtils.getDictLabel(dictType, value, separator));
+        return StringUtils.isEmpty(s)?value:s;
     }
 
     /**
@@ -1244,7 +1270,7 @@
      * 杞崲鍗曞厓鏍煎�间负鐩爣绫诲瀷
      */
     private Object convertValue(Object val, Class<?> fieldType, Excel attr) {
-        String strVal = Convert.toStr(val).trim();
+        String strVal = Convert.toStr(val);
         if (StringUtils.isEmpty(strVal)) return null;
 
         try {
@@ -1351,6 +1377,10 @@
      * @return 瀛楀吀鍊�
      */
     public static String reverseDictByExp(String dictLabel, String dictType, String separator) {
+        if (StringUtils.isEmpty(dictLabel))
+        {
+            return StringUtils.EMPTY;
+        }
         return DictUtils.getDictValue(dictType, dictLabel, separator);
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0