public static void main(String[] args) {
try (
InputStream is = new FileInputStream(new File("F:/Excel/sss.xlsx"));
Workbook workbook = StreamingReader.builder()
.rowCacheSize(100)
.bufferSize(4096)
.open(is)) {
for (Sheet sheet : workbook){
System.out.println(sheet.getSheetName());
for (Row r : sheet) {
for (Cell c : r) {
System.out.println(c.getStringCellValue());
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
问题
当使用xlsx-streamer读取excel的时候,如果文件达到500M左右,会抛出大概如下异常:
"Zip bomb detected! The file would exceed the max size of the expanded data in the zip-file.This may indicates that the file is used to inflate memory usage and thus could pose a security risk.You can adjust this limit via ZipSecureFile.setMaxEntrySize() if you need to work with files which are very large.
原因是poi进行了限制 [0-4GB]:
public static void setMaxEntrySize(long maxEntrySize) {
if (maxEntrySize < 0 || maxEntrySize > 0xFFFFFFFFL) { // don't use MAX_ENTRY_SIZE here!
throw new IllegalArgumentException("Max entry size is bounded [0-4GB], but had " + maxEntrySize);
}
MAX_ENTRY_SIZE = maxEntrySize;
}