mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix excel sax bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user