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

@@ -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);
}
}