1
我正在研究需要读取大型xlsx文件的需求,其中包含超过一百万条记录。 apache POI在读取大文件时效率并不高。因此,我在使用下面的API,其中添加了使用apache POI/monitorjbl/excel-streaming-reader读取大型xlsx文件中的空白单元问题
https://github.com/monitorjbl/excel-streaming-reader这是一个围绕该流式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)
如果行的细胞是空则在开关的情况下即cell.getCelltype投掷空指针。我已经修改代码改为空细胞作为空白单元格,但其不支持
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()) {
}
}
如果我用细胞的细胞= row.getCell(I,Row.CREATE_NULL_AS_BLANK)读取空单元格为空白我得到以下问题。请帮我解决这个
com.monitorjbl.xlsx.exceptions.NotSupportedException
at com.monitorjbl.xlsx.impl.StreamingRow.getCell(StreamingRow.java:108)
试试这个,如果(Cell.CELL_TYPE_BLANK)Cell.setValue(”“); –
为什么不在你的switch语句之前添加一个'if(cell!= null)'? – Gagravarr
我将xlsx转换为csv。如果任何单元格为空,我必须将其视为空白并将空字符串(“”)视为该字段的csv数据。 – Kiran