Java中使用POI读取大的Excel文件或者输入流时发生out of memory异常参考解决方案

excel-streaming-reader

excel-streaming-reader

Java中使用POI读取大的Excel文件或者输入流时发生out of memory异常参考解决方案

1
2
3
4
5
<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
<version>1.2.0</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
try (
InputStream is = new FileInputStream(new File("/path/to/workbook.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());
}
}
}
}

easyexcel

easyexcel