From a5edca4c62ea99418dcaa5d792947b1bab7fe8b2 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期三, 17 十二月 2025 23:08:36 +0800
Subject: [PATCH] 修改了对应代码

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java |   50 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
index 90f7cc9..eb1d918 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
@@ -554,21 +554,35 @@
         style.setFont(dataFont);
         styles.put("data", style);
 
-        style = wb.createCellStyle();
-        style.cloneStyleFrom(styles.get("data"));
-        style.setAlignment(HorizontalAlignment.CENTER);
-        style.setVerticalAlignment(VerticalAlignment.CENTER);
-        // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
-        style.setWrapText(true);
-        style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
-        Font headerFont = wb.createFont();
-        headerFont.setFontName("Arial");
-        headerFont.setFontHeightInPoints((short) 10);
-        headerFont.setBold(true);
-        headerFont.setColor(IndexedColors.WHITE.getIndex());
-        style.setFont(headerFont);
-        styles.put("header", style);
+        // 鍒涘缓琛ㄥご鏍峰紡鏄犲皠锛屾牴鎹瓻xcel娉ㄨВ鍔ㄦ�佺敓鎴�
+        Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
+        for (Object[] os : fields)
+        {
+            Excel excel = (Excel) os[1];
+            String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
+            if (!headerStyles.containsKey(key))
+            {
+                 style = wb.createCellStyle();
+                style.cloneStyleFrom(styles.get("data"));
+                style.setAlignment(HorizontalAlignment.CENTER);
+                style.setVerticalAlignment(VerticalAlignment.CENTER);
+                // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+                style.setWrapText(true);
+                // 鏍规嵁娉ㄨВ璁剧疆琛ㄥご鑳屾櫙鑹� - 宸叉敞閲婏紝琛ㄥご涓嶆樉绀鸿儗鏅壊
+                /*if (excel.headerBackgroundColor() != IndexedColors.WHITE) {
+                    style.setFillForegroundColor(excel.headerBackgroundColor().index);
+                    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                }*/
+                Font headerFont = wb.createFont();
+                headerFont.setFontName("Arial");
+                headerFont.setFontHeightInPoints((short) 10);
+                headerFont.setBold(false);
+                headerFont.setColor(excel.headerColor().index);
+                style.setFont(headerFont);
+                headerStyles.put(key, style);
+            }
+        }
+        styles.putAll(headerStyles);
 
         style = wb.createCellStyle();
         style.setAlignment(HorizontalAlignment.CENTER);
@@ -614,7 +628,9 @@
         // 鍐欏叆鍒椾俊鎭�
         cell.setCellValue(attr.name());
         setDataValidation(attr, row, column);
-        cell.setCellStyle(styles.get("header"));
+        // 鏍规嵁Excel娉ㄨВ鍔ㄦ�侀�夋嫨琛ㄥご鏍峰紡
+        String key = StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor());
+        cell.setCellStyle(styles.get(key));
         return cell;
     }
 
@@ -673,7 +689,7 @@
             sheet.setColumnWidth(column, 6000);
         } else {
             // 璁剧疆鍒楀
-            sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 200));
+            sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
         }
         // 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀�.
         if (StringUtils.isNotEmpty(attr.prompt())) {

--
Gitblit v1.9.1