From b1b8a29a3cdd463ce58161dec0e392a0898238a6 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 26 Aug 2021 23:56:38 +0800 Subject: [PATCH] fix excel sax bug --- CHANGELOG.md | 1 + .../java/cn/hutool/poi/excel/sax/Excel03SaxReader.java | 4 ++-- .../java/cn/hutool/poi/excel/sax/Excel07SaxReader.java | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 232191f37..e6ea0f424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ ### 🐞Bug修复 * 【core 】 修复MapUtil.sort比较器不一致返回原map的问题(issue#I46AQJ@Gitee) * 【core 】 修复JSONSupport默认循环引用导致的问题(issue#1779@Github) +* 【poi 】 修复ExcelUtil.readBySax资源没有释放问题(issue#1789@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java index 9319e5d27..0f1f3d184 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java @@ -107,8 +107,8 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader { @Override public Excel07SaxReader read(File file, String idOrRidOrSheetName) throws POIException { - try { - return read(OPCPackage.open(file), idOrRidOrSheetName); - } catch (InvalidFormatException e) { + try (OPCPackage open = OPCPackage.open(file, PackageAccess.READ);){ + return read(open, idOrRidOrSheetName); + } catch (InvalidFormatException | IOException e) { throw new POIException(e); } }