| | |
| | | } |
| | | } |
| | | |
| | | /** 按 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(); |