diff --git a/pom.xml b/pom.xml
index f85fd407..0e5b7909 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.alibaba
easyexcel
- 2.0.0-beta1
+ 2.0.0-beta2
jar
easyexcel
diff --git a/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java b/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
index dcf1d844..256fb517 100644
--- a/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
+++ b/src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
@@ -131,6 +131,20 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
} catch (Throwable e) {
throw new ExcelAnalysisException("Can not close IO", e);
}
+ try {
+ if (readWorkbookHolder.getOpcPackage() != null) {
+ readWorkbookHolder.getOpcPackage().close();
+ }
+ } catch (Throwable e) {
+ throw new ExcelAnalysisException("Can not close IO", e);
+ }
+ try {
+ if (readWorkbookHolder.getPoifsFileSystem() != null) {
+ readWorkbookHolder.getPoifsFileSystem().close();
+ }
+ } catch (Throwable e) {
+ throw new ExcelAnalysisException("Can not close IO", e);
+ }
}
@Override
diff --git a/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java b/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
index 996e33ae..2b67b439 100644
--- a/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
+++ b/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
@@ -73,6 +73,7 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelExecutor {
this.analysisContext = context;
this.records = new TreeMap();
this.poifsFileSystem = poifsFileSystem;
+ analysisContext.readWorkbookHolder().setPoifsFileSystem(poifsFileSystem);
}
@Override
diff --git a/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java b/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
index 748306a7..f16f9267 100644
--- a/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
+++ b/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
@@ -59,6 +59,7 @@ public class XlsxSaxAnalyser implements ExcelExecutor {
ReadWorkbookHolder readWorkbookHolder = analysisContext.readWorkbookHolder();
OPCPackage pkg = readOpcPackage(readWorkbookHolder, decryptedStream);
+ readWorkbookHolder.setOpcPackage(pkg);
PackagePart sharedStringsTablePackagePart =
pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType()).get(0);
diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
index bfcc0506..9b77c8c2 100644
--- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
+++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
@@ -6,6 +6,8 @@ import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,6 +92,14 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
* Prevent repeating sheet
*/
private Set hasReadSheet;
+ /**
+ * Package
+ */
+ private OPCPackage opcPackage;
+ /**
+ * File System
+ */
+ private POIFSFileSystem poifsFileSystem;
public ReadWorkbookHolder(ReadWorkbook readWorkbook) {
super(readWorkbook, null, readWorkbook.getConvertAllFiled());
@@ -232,6 +242,22 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.defaultReturnMap = defaultReturnMap;
}
+ public OPCPackage getOpcPackage() {
+ return opcPackage;
+ }
+
+ public void setOpcPackage(OPCPackage opcPackage) {
+ this.opcPackage = opcPackage;
+ }
+
+ public POIFSFileSystem getPoifsFileSystem() {
+ return poifsFileSystem;
+ }
+
+ public void setPoifsFileSystem(POIFSFileSystem poifsFileSystem) {
+ this.poifsFileSystem = poifsFileSystem;
+ }
+
@Override
public HolderEnum holderType() {
return HolderEnum.WORKBOOK;
diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
new file mode 100644
index 00000000..dd891055
--- /dev/null
+++ b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
@@ -0,0 +1,54 @@
+package com.alibaba.easyexcel.test.temp;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.support.ExcelTypeEnum;
+import com.alibaba.fastjson.JSON;
+
+/**
+ * 临时测试
+ *
+ * @author Jiaju Zhuang
+ **/
+@Ignore
+public class Lock2Test {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Lock2Test.class);
+
+ @Test
+ public void test() throws Exception {
+ File file = new File("D:\\test\\珠海2.xlsx");
+
+ List