diff --git a/CHANGELOG.md b/CHANGELOG.md index 634ef6696..f52170d5a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * 【core 】 优化IndexedComparator性能(pr#1240@Gitee) * 【http 】 改进ContentType.get忽略空格(pr#3664@Github) * 【http 】 CompressUtil.createExtractor支持tgz自动识别(pr#3674@Github) +* 【poi 】 ExcelWriter.autoSizeColumn增加可选widthRatio参数,可配置中文字符宽度倍数(pr#3689@Github) ### 🐞Bug修复 * 【core 】 修复因RFC3986理解有误导致的UrlPath处理冒号转义问题(issue#IAAE88@Gitee) diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/BigExcelWriter.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/BigExcelWriter.java index f8f86947b..bc6ed492e 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/BigExcelWriter.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/BigExcelWriter.java @@ -152,11 +152,7 @@ public class BigExcelWriter extends ExcelWriter { @Override public BigExcelWriter autoSizeColumnAll() { - final SXSSFSheet sheet = (SXSSFSheet) this.sheet; - sheet.trackAllColumnsForAutoSizing(); - super.autoSizeColumnAll(); - sheet.untrackAllColumnsForAutoSizing(); - return this; + return autoSizeColumnAll(0); } @Override diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java index a718a879c..e101516b8 100755 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelWriter.java @@ -305,9 +305,10 @@ public class ExcelWriter extends ExcelBase { * @since 5.8.30 */ public ExcelWriter autoSizeColumn(int columnIndex, boolean useMergedCells, float widthRatio) { - sheet.autoSizeColumn(columnIndex, useMergedCells); if (widthRatio > 0) { sheet.setColumnWidth(columnIndex, (int) (sheet.getColumnWidth(columnIndex) * widthRatio)); + } else { + sheet.autoSizeColumn(columnIndex, useMergedCells); } return this; }