diff --git a/yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java b/yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java index 2c0db2d4429a11543e63e11165cc6226a50a8b7f..24f824b336273d80160b50b15a742f6046409b8d 100755 --- a/yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java +++ b/yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java @@ -201,7 +201,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { // 创建一行 Row row = sheet.createRow(rowIndex); row.setHeight(getUnit(rowHeight)); - Cell cell = createCell(row, 0, content); + Cell cell = createCell(row, 0, content, false); // 这里是åˆå¹¶excelä¸å¤šåˆ—为1列 CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex, 0, columnLength); sheet.addMergedRegion(region); @@ -223,7 +223,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { // 写入列头 for (TableHeadItem headItem : head.getColumns()) { Row row = rows[headItem.getRow()]; - Cell cell = createCell(row, headItem.getColumn(), headItem.getName()); + Cell cell = createCell(row, headItem.getColumn(), headItem.getName(), true); // 判æ–是å¦éœ€è¦åˆå¹¶åˆ—头 if (headItem.getColumnCell() > 1 || headItem.getRowCell() > 1) { @@ -305,7 +305,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { String value = StringHelper.getFirst(rowHandle.get(t, columnName)); // 当ä¸éœ€è¦åˆå¹¶åŽ†å²è®°å½•æ—¶ï¼Œåˆ™åˆ›å»ºæ–°çš„内容 - Cell cell = createCell(row, columnPos, value); + Cell cell = createCell(row, columnPos, value, true); // 判æ–列是å¦éœ€è¦åˆå¹¶ if (column.isMerger()) { ExcelMergerData mergerData = mergerGroupData.get(column.getMegerGroup()); @@ -418,16 +418,18 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { * @param content * @return */ - private Cell createCell(Row row, int column, String content) { + private Cell createCell(Row row, int column, String content, boolean isMax) { // 获å–å—节数ã€ç”¨äºŽè®¾ç½®æœ€å¤§å®½åº¦ - int chinaCount = 0; - Matcher matcher = chinese.matcher(content); - while (matcher.find()) { - chinaCount++; + if (isMax) { + int chinaCount = 0; + Matcher matcher = chinese.matcher(content); + while (matcher.find()) { + chinaCount++; + } + int bytes = (content.length() - chinaCount) + (int) Math.round(chinaCount * 1.5); + int maxBytes = Math.max(columnBytes.getOrDefault(column, 0), bytes); + columnBytes.put(column, maxBytes); } - int bytes = (content.length() - chinaCount) + (int) Math.round(chinaCount * 2); - int maxBytes = Math.max(columnBytes.getOrDefault(column, 0), bytes); - columnBytes.put(column, maxBytes); Cell cell = row.createCell(column); cell.setCellStyle(style);