From 5d91a329768a2a86e01e4b9b6bc6a2b939b87adb Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期五, 16 一月 2026 22:48:51 +0800
Subject: [PATCH] 修改了对应代码

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java |   81 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
index 822c066..04a1881 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
@@ -325,7 +325,7 @@
                     // 濡傛灉鏄痠ndex涓�1鐨剆heet锛岃缃《绔爣棰樿
 
                         // 灏嗙1琛岋紙绱㈠紩涓�0锛夎缃负姣忛〉閲嶅鐨勬爣棰樿
-                        sheet.setRepeatingRows(CellRangeAddress.valueOf("$1:$4"));
+                        sheet.setRepeatingRows(CellRangeAddress.valueOf("$1:$5"));
                      row = sheet.createRow(0);
                     row.setHeight((short) (37*20));
 
@@ -532,6 +532,10 @@
                 row = sheet.createRow(i + 5 );
             else
                 row = sheet.createRow(i + 1 );
+            // 绗竴姝ワ細璁㏄OI鑷姩璁$畻閫傞厤鍐呭鐨勮楂�
+         //   sheet.autoSizeRow(0);
+            // 绗簩姝ワ細鑾峰彇鑷姩璁$畻鍚庣殑琛岄珮
+
 
             // 寰楀埌瀵煎嚭瀵硅薄.
             T vo = (T) list.get(i);
@@ -542,7 +546,9 @@
                 // 璁剧疆瀹炰綋绫荤鏈夊睘鎬у彲璁块棶
                 field.setAccessible(true);
                 this.addCell(excel, row, vo, field, column++);
+
             }
+
         }
     }
 
@@ -730,7 +736,7 @@
         Cell cell = null;
         try {
             // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
-            row.setHeight((short) -1);
+          //  row.setHeight((short) -1);
             // 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
             if (attr.isExport()) {
                 // 鍒涘缓cell
@@ -745,7 +751,13 @@
                 } else if (align == HorizontalAlignment.RIGHT) {
                     styleKey = "data3";
                 }
-                cell.setCellStyle(styles.get(styleKey));
+                // 鑾峰彇骞朵慨鏀规牱寮�
+                CellStyle style = styles.get(styleKey);
+                Workbook workbook = row.getSheet().getWorkbook();
+                CellStyle newStyle = workbook.createCellStyle();
+                newStyle.cloneStyleFrom(style);
+                newStyle.setWrapText(true); // 鍏抽敭锛氬惎鐢ㄨ嚜鍔ㄦ崲琛�
+                cell.setCellStyle(newStyle);
 
                 // 鐢ㄤ簬璇诲彇瀵硅薄涓殑灞炴��
                 Object value = getTargetValue(vo, field, attr);
@@ -762,6 +774,9 @@
                     // 璁剧疆鍒楃被鍨�
                     setCellVo(value, attr, cell);
                 }
+
+                adjustRowHeightAfterSetValue(row, cell, value);
+
                 addStatisticsData(column, Convert.toStr(value), attr);
             }
         } catch (Exception e) {
@@ -769,7 +784,65 @@
         }
         return cell;
     }
+    /**
+     * 璁剧疆鍊煎悗璋冩暣琛岄珮
+     */
+    private void adjustRowHeightAfterSetValue(Row row, Cell cell, Object value) {
+        if (value == null) return;
 
+        String text = value.toString();
+        Sheet sheet = row.getSheet();
+
+        // 1. 璁$畻鑷姩楂樺害锛堝熀浜庡唴瀹癸級
+        short autoHeight = calculateSimpleAutoHeight(text, cell);
+
+        // 2. 鑾峰彇褰撳墠琛岄珮
+        short currentHeight = row.getHeight();
+        if (currentHeight == -1) {
+            currentHeight = sheet.getDefaultRowHeight();
+        }
+
+        // 3. 浣跨敤杈冨ぇ鐨勯珮搴︼紙鑷姩璁$畻鐨勯珮搴︽垨褰撳墠楂樺害锛�
+        short baseHeight = (short) Math.max(currentHeight, autoHeight);
+        System.out.println(baseHeight+"aaaaaaaaatttttttt");
+        // 4. 鍦ㄥ熀纭�涓婂鍔犻澶栭珮搴︼紙100鍗曚綅 = 5鐐癸級
+        short extraHeight = 80;
+        short newHeight = (short) (baseHeight + extraHeight);
+
+        // 5. 闄愬埗鏈�澶ч珮搴�
+        short maxHeight = (short) 4000; // 100鐐�
+        row.setHeight((short) Math.min(maxHeight,newHeight));
+    }
+
+    /**
+     * 绠�鍖栫殑鑷姩楂樺害璁$畻
+     */
+    private short calculateSimpleAutoHeight(String text, Cell cell) {
+        if (text == null || text.isEmpty()) return 0;
+
+        Sheet sheet = cell.getSheet();
+        int colIndex = cell.getColumnIndex();
+
+        // 鑾峰彇鍒楀锛堝瓧绗︽暟锛�
+        int colWidthChars = sheet.getColumnWidth(colIndex) / 256;
+        if (colWidthChars <= 0) colWidthChars = 10;
+
+        // 璁$畻鏂囨湰琛屾暟
+        int lines = 1;
+        if (text.contains("\n")) {
+            // 鏈夋樉寮忔崲琛�
+            String[] parts = text.split("\n");
+            for (String part : parts) {
+                lines += Math.max(1, (int) Math.ceil(part.length() * 1.5 / colWidthChars));
+            }
+        } else {
+            // 鑷姩鎹㈣
+            lines = (int) Math.ceil(text.length() * 1.5 / colWidthChars);
+        }
+
+        // 姣忚楂樺害锛氬亣璁�18鐐癸紙360 POI鍗曚綅锛�
+        return (short) (lines * 360);
+    }
     /**
      * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
      *
@@ -1101,7 +1174,7 @@
            // header.setFontName("瀹嬩綋");4
            // header.setFontSize((short) 10);
             // 璁剧疆椤电湁鍐呭
-            hssfSheet.setMargin(Sheet.HeaderMargin, 1.34);
+            hssfSheet.setMargin(Sheet.HeaderMargin, 1.43);
             header.setRight("&\"瀹嬩綋,Bold\"鍏� &N 椤�   绗� &P 椤�");
         }
         // 濡傛灉鏄痠ndex涓�1鐨剆heet锛岃缃《绔爣棰樿

--
Gitblit v1.9.1