From d39e4f7d839167c16425086dfa2f8747bccfdff9 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 05 十一月 2026 17:39:01 +0800
Subject: [PATCH] feat: 打通销售采购财务闭环并完成累计业务优化

---
 yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ColumnWidthMatchStyleStrategy.java |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ColumnWidthMatchStyleStrategy.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ColumnWidthMatchStyleStrategy.java
index 49a5b31..69100bf 100644
--- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ColumnWidthMatchStyleStrategy.java
+++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ColumnWidthMatchStyleStrategy.java
@@ -41,6 +41,14 @@
         if (columnWidth < 0) {
             return;
         }
+        // 瀛楁涓婂0鏄庝簡 @ColumnWidth 鏃讹紝浠ュ0鏄庡�间负涓嬮檺銆�
+        // 鍚﹀垯娉ㄨВ鍊间細琚湰绛栫暐瑕嗙洊锛欵asyExcel 鑷繁鐨� AbstractHeadColumnWidthStyleStrategy锛堣礋璐f妸
+        // @ColumnWidth 鍐欒繘鍒楀锛変笌鏈瓥鐣� order 鐩稿悓锛堥兘鏄� 0锛屾寜娉ㄥ唽椤哄簭鎺掑湪鍓嶉潰锛夛紝
+        // 鏈瓥鐣ユ寜鍐呭闀垮害鍚庡啓锛岀洿鎺ユ妸澹版槑鐨勫搴﹀啿鎺� 鈥斺�� 渚嬪銆�2026-10-13 10:10:20銆嶅彧鏈� 19 涓瓧绗︼紝
+        // 鍒楀灏卞仠鍦� 19锛屽0鏄庡啀澶т篃娌$敤銆傚彇鏈�澶у�煎悗锛屾敞瑙f垚浜嗗唴瀹归暱搴︾殑涓嬮檺锛屽彧鏀惧涓嶆敹绐勩��
+        if (isHead && head != null && head.getColumnWidthProperty() != null) {
+            columnWidth = Math.max(columnWidth, head.getColumnWidthProperty().getWidth());
+        }
         if (columnWidth > MAX_COLUMN_WIDTH) {
             columnWidth = MAX_COLUMN_WIDTH;
         }
@@ -51,10 +59,31 @@
         }
     }
 
+    /** 鎸� Excel 鍒楀浼拌琛ㄥご锛氫腑鏃ラ煩瀹藉瓧绗﹀崰涓ゆ牸锛屽苟涓鸿竟璺濈暀鍑虹┖闂淬�� */
+    private int headerWidth(String text) {
+        int widest = 0;
+        int line = 0;
+        for (int offset = 0; offset < text.length();) {
+            int cp = text.codePointAt(offset);
+            offset += Character.charCount(cp);
+            if (cp == '\n' || cp == '\r') {
+                widest = Math.max(widest, line);
+                line = 0;
+                continue;
+            }
+            Character.UnicodeScript script = Character.UnicodeScript.of(cp);
+            boolean wide = script == Character.UnicodeScript.HAN || script == Character.UnicodeScript.HIRAGANA
+                    || script == Character.UnicodeScript.KATAKANA || script == Character.UnicodeScript.HANGUL
+                    || (cp >= 0xff01 && cp <= 0xff60) || (cp >= 0xffe0 && cp <= 0xffe6);
+            line += wide ? 2 : 1;
+        }
+        return Math.max(widest, line);
+    }
+
     @SuppressWarnings("EnhancedSwitchMigration")
     private Integer dataLength(List<WriteCellData<?>> cellDataList, Cell cell, Boolean isHead) {
         if (isHead) {
-            return cell.getStringCellValue().getBytes().length;
+            return Math.max(12, headerWidth(cell.getStringCellValue()) + 3);
         }
         WriteCellData<?> cellData = cellDataList.get(0);
         CellDataTypeEnum type = cellData.getType();

--
Gitblit v1.9.3