From 537dfc80b7f2adb9fdaaf66ca0f473a7b21f256c Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 7 Jul 2020 16:39:10 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/poi/excel/sax/ExcelSaxUtil.java | 6 +++++- .../test/java/cn/hutool/poi/excel/test/ExcelReadTest.java | 1 - .../java/cn/hutool/poi/excel/test/ExcelSaxReadTest.java | 6 ++---- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba3fcd7c..a5b15c6de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * 【core 】 修复ZipUtil没有调用finish问题(issue#944@Github) * 【extra 】 修复Ftp中ArrayList长度为负问题(pr#136@Github) * 【core 】 修复Dict中putAll大小写问题(issue#I1MU5B@Gitee) +* 【core 】 修复POI中sax读取数字判断错误问题(issue#931@Github) ------------------------------------------------------------------------------------------------------------- ## 5.3.8 (2020-06-16) diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/ExcelSaxUtil.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/ExcelSaxUtil.java index e475e2f25..b8acb25ce 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/ExcelSaxUtil.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/ExcelSaxUtil.java @@ -73,7 +73,11 @@ public class ExcelSaxUtil { } break; case NUMBER: - result = getNumberValue(value, numFmtString); + try{ + result = getNumberValue(value, numFmtString); + }catch (NumberFormatException e){ + result = value; + } break; case DATE: try { diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java index 85742679c..b474fa034 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelReadTest.java @@ -213,5 +213,4 @@ public class ExcelReadTest { final ExcelReader reader = ExcelUtil.getReader("merge_test.xlsx"); reader.read((cell, value)-> Console.log("{}, {} {}", cell.getRowIndex(), cell.getColumnIndex(), value)); } - } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelSaxReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelSaxReadTest.java index e304ebfda..88d34d4d0 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelSaxReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelSaxReadTest.java @@ -115,10 +115,8 @@ public class ExcelSaxReadTest { public void readBlankTest(){ File file = new File("D:/test/b.xlsx"); - ExcelUtil.readBySax(file, 0, (sheetIndex, rowIndex, rowList) -> { - rowList.forEach(System.out::println); - }); + ExcelUtil.readBySax(file, 0, (sheetIndex, rowIndex, rowList) -> rowList.forEach(Console::log)); - ExcelUtil.getReader(file).read().forEach(System.out::println); + ExcelUtil.getReader(file).read().forEach(Console::log); } }