我想从Excel(.xlsx)文件中读取超过60万行。
我正在使用Apache POI和xlsx-streamer。
<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
<version>1.2.0</version>
</dependency>
Apache poi版本是3.15,因为上述版本不支持xlsx-streamer
我只想迭代特定的列。我尝试过的是:
File myFile = new File("testFile.xlsx");
FileInputStream fis = new FileInputStream(myFile);
Workbook workbook = StreamingReader.builder().bufferSize(4096).open(fis);
// Sheet sheet = workbook.getSheetAt(0);
for (Sheet sheet : workbook) {
for (int r = 0; r < sheet.getLastRowNum(); r++) {
Row rr = sheet.getRow(r);
for (int c = 1; c < rr.getLastCellNum(); c++) {
Cell cell = rr.getCell(c);
System.out.println("" + cell.getStringCellValue());
}
}
我得到的这种异常很少警告
Exception in thread "main" java.lang.UnsupportedOperationException
at com.monitorjbl.xlsx.impl.StreamingSheet.getRow(StreamingSheet.java:102)
at ReadExcel.main(ReadExcel.java:35)
第35行是
Row rr = sheet.getRow(r);