fix excel sax bug

This commit is contained in:
Looly 2021-08-26 23:56:38 +08:00
parent aeb9c723c5
commit b1b8a29a3c
3 changed files with 7 additions and 5 deletions

View File

@ -30,6 +30,7 @@
### 🐞Bug修复
* 【core 】 修复MapUtil.sort比较器不一致返回原map的问题issue#I46AQJ@Gitee
* 【core 】 修复JSONSupport默认循环引用导致的问题issue#1779@Github
* 【poi 】 修复ExcelUtil.readBySax资源没有释放问题issue#1789@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -107,8 +107,8 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader<Excel03Sax
// ------------------------------------------------------------------------------ Read start
@Override
public Excel03SaxReader read(File file, String idOrRidOrSheetName) throws POIException {
try {
return read(new POIFSFileSystem(file), idOrRidOrSheetName);
try (POIFSFileSystem poifsFileSystem = new POIFSFileSystem(file, true)) {
return read(poifsFileSystem, idOrRidOrSheetName);
} catch (IOException e) {
throw new POIException(e);
}

View File

@ -9,6 +9,7 @@ import cn.hutool.poi.exceptions.POIException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import java.io.File;
@ -55,9 +56,9 @@ public class Excel07SaxReader implements ExcelSaxReader<Excel07SaxReader> {
@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);
}
}