Java 使用apache POI/monitorjbl/excel streaming reader读取大型xlsx文件中的空白单元格时出现问题

Java 使用apache POI/monitorjbl/excel streaming reader读取大型xlsx文件中的空白单元格时出现问题,java,apache-poi,Java,Apache Poi,我工作的要求,我需要读取大型xlsx文件包含超过一百万条记录。ApachePOI在读取大文件时内存效率不高。因此,我使用下面的API添加 它是流式API的包装器,同时保留标准POI API的语法。除了读取行中的空白单元格外,所有操作都正常。如果单元格为空,则上述API将抛出空指针 for(int i=0; i<=expectedColumns-1; i++) { Cell cell = row.getCell(i); switch (cel

我工作的要求,我需要读取大型xlsx文件包含超过一百万条记录。ApachePOI在读取大文件时内存效率不高。因此,我使用下面的API添加

它是流式API的包装器,同时保留标准POI API的语法。除了读取行中的空白单元格外,所有操作都正常。如果单元格为空,则上述API将抛出空指针

       for(int i=0; i<=expectedColumns-1; i++) {
              Cell cell = row.getCell(i);
    switch (cell.getCellType()) {
    }
            }
java.lang.NullPointerException
at test.XLSXToCSVConverterStreamer.xlsx(XLSXToCSVConverterStreamer.java:67)
at test.XLSXToCSVConverterStreamer.main(XLSXToCSVConverterStreamer.java:164)

流式excel不支持许多方法,但它提供了读取大型excel文件的优势。您可以从以下行中读取空白单元格(使用流式Excel阅读器V1.1.0)

boolean标志=false;
int lastcolno=row.getLastCellNum();
for(colno=0;colno
如果(Cell.Cell\u TYPE\u BLANK)Cell.setValue(“”),请尝试此操作;为什么不在switch语句之前添加一个if(cell!=null)呢?我正在将xlsx转换为csv。如果任何一个单元格是空的,我必须把它看作空白,并将空白字符串(“”)作为CSV数据用于该字段。同意Gagravarr。如果要在单元格为空时写入“”,可以在ELSE块中执行。
    for(int i=0; i<=expectedColumns-1; i++) {
      //Cell cell = row.getCell(i);
     Cell cell = row.getCell(i, Row.CREATE_NULL_AS_BLANK);
switch (cell.getCellType()) {
}
    }
com.monitorjbl.xlsx.exceptions.NotSupportedException
at com.monitorjbl.xlsx.impl.StreamingRow.getCell(StreamingRow.java:108)
boolean flag = false;
int lastcolno = row.getLastCellNum();

for (colno = 0; colno < lastcolno; colno++) {
    colFlag = isColumnEmpty(row, colno);

    if (flag == true)
        break;
}

if (colFlag == true) {
     System.out.println("In index row, column no: "
            + (colno + 1) + " is empty");
}

public static boolean isColumnEmpty(Row row, int colno) {
     Cell c = row.getCell(colno);
     if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK)
            return true;
return false;
}