From e7dd8b490661c994c414c0edc2da1854d9bcef82 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 05 十一月 2026 13:33:12 +0800
Subject: [PATCH] feat(excel): 优化Excel列宽与必填标记并支持巡检附件
---
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ColumnWidthMatchStyleStrategy.java | 23 ++++++++++++++++++++++-
1 files changed, 22 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 3ed512d..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
@@ -59,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