diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/ExcelSaxUtil.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/ExcelSaxUtil.java index 92cc45cc6..80be07baf 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/ExcelSaxUtil.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/ExcelSaxUtil.java @@ -44,9 +44,13 @@ import java.io.InputStream; */ public class ExcelSaxUtil { - // 填充字符串 + /** + * 填充字符串 + */ public static final char CELL_FILL_CHAR = '@'; - // 列的最大位数 + /** + * 列的最大位数 + */ public static final int MAX_CELL_BIT = 3; /** @@ -103,13 +107,6 @@ public class ExcelSaxUtil { result = value; } break; - case NUMBER: - try { - result = getNumberValue(value, numFmtString); - } catch (final NumberFormatException e) { - result = value; - } - break; case DATE: try { result = getDateValue(value); @@ -118,7 +115,11 @@ public class ExcelSaxUtil { } break; default: - result = value; + try { + result = getNumberValue(value, numFmtString); + } catch (final NumberFormatException e) { + result = value; + } break; } return result; diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/SheetDataSaxHandler.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/SheetDataSaxHandler.java index 07de1ddfb..fff25e7f9 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/SheetDataSaxHandler.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/sax/SheetDataSaxHandler.java @@ -267,6 +267,7 @@ public class SheetDataSaxHandler extends DefaultHandler { value = new FormulaCellValue(StrUtil.trim(lastFormula), ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStrings, this.numFmtString)); }else{ + // since 6.0.0,默认的cellDataType是NULL而非NUMBER value = ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStrings, this.numFmtString); } addCellValue(curCell++, value); diff --git a/hutool-poi/src/test/java/org/dromara/hutool/poi/excel/ExcelSaxReadTest.java b/hutool-poi/src/test/java/org/dromara/hutool/poi/excel/ExcelSaxReadTest.java index a8e817173..aac0b483f 100644 --- a/hutool-poi/src/test/java/org/dromara/hutool/poi/excel/ExcelSaxReadTest.java +++ b/hutool-poi/src/test/java/org/dromara/hutool/poi/excel/ExcelSaxReadTest.java @@ -204,7 +204,7 @@ public class ExcelSaxReadTest { // 非日期格式不做转换 Assertions.assertEquals("112233", rows.get(2)); // 读取实际值,而非带有格式处理过的值 - Assertions.assertEquals("1000", rows.get(3)); + Assertions.assertEquals("1000.0", rows.get(3)); Assertions.assertEquals("2012-12-21 00:00:00", rows.get(4)); }