From 7050927b0a56485bdd83c597849586e39af5b6fe Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 21 Mar 2022 13:33:39 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 4 +++- .../src/main/java/cn/hutool/poi/excel/ExcelUtil.java | 4 ++-- .../cn/hutool/poi/excel/sax/Excel07SaxReader.java | 11 ++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24a0d664b..caed37874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.0 (2022-03-20) +# 5.8.0 (2022-03-21) ### ❌不兼容特性 * 【db 】 【不向下兼容 】增加MongoDB4.x支持返回MongoClient变更(pr#568@Gitee) @@ -14,6 +14,7 @@ * 【core 】 【可能兼容问题】Base62分离编码和解码,增加inverted模式支持 * 【core 】 【兼容问题 】PunyCode参数由String改为Charsequence * 【cron 】 【可能兼容问题】SimpleValueParser改名为AbsValueParser,改为abstract +* 【poi 】 【可能兼容问题】ExcelUtil.getBigWriter返回值改为BigExcelWriter ### 🐣新特性 * 【http 】 HttpRequest.form采用TableMap方式(issue#I4W427@Gitee) @@ -46,6 +47,7 @@ * 【core 】 修复CopyOptions中fieldNameEditor无效问题(issue#2202@Github) * 【json 】 修复JSON对Map.Entry的解析问题 * 【core 】 修复MapConverter中map与map转换兼容问题 +* 【poi 】 解决sax读取时,POI-5.2.x兼容性问题 ------------------------------------------------------------------------------------------------------------- # 5.7.22 (2022-03-01) diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelUtil.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelUtil.java index 17860c8ae..8db7e1ced 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelUtil.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelUtil.java @@ -345,7 +345,7 @@ public class ExcelUtil { * @return {@link BigExcelWriter} * @since 4.1.13 */ - public static ExcelWriter getBigWriter() { + public static BigExcelWriter getBigWriter() { try { return new BigExcelWriter(); } catch (NoClassDefFoundError e) { @@ -362,7 +362,7 @@ public class ExcelUtil { * @return {@link BigExcelWriter} * @since 4.1.13 */ - public static ExcelWriter getBigWriter(int rowAccessWindowSize) { + public static BigExcelWriter getBigWriter(int rowAccessWindowSize) { try { return new BigExcelWriter(rowAccessWindowSize); } catch (NoClassDefFoundError e) { diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel07SaxReader.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel07SaxReader.java index b50034cb3..2c4ec4b71 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel07SaxReader.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel07SaxReader.java @@ -3,6 +3,7 @@ package cn.hutool.poi.excel.sax; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.sax.handler.RowHandler; import cn.hutool.poi.exceptions.POIException; @@ -127,13 +128,9 @@ public class Excel07SaxReader implements ExcelSaxReader { } // 获取共享字符串表 - try { - this.handler.sharedStrings = xssfReader.getSharedStringsTable(); - } catch (IOException e) { - throw new IORuntimeException(e); - } catch (InvalidFormatException e) { - throw new POIException(e); - } + // POI-5.2.0开始返回值有所变更,导致实际使用时提示方法未找到,此处使用反射调用,解决不同版本返回值变更问题 + //this.handler.sharedStrings = xssfReader.getSharedStringsTable(); + this.handler.sharedStrings = ReflectUtil.invoke(xssfReader, "getSharedStringsTable"); return readSheets(xssfReader, idOrRidOrSheetName); }