我有一个巨大的excel文件,里面有很多列,看起来像这样:
Column1 Column2 Column3 Column4 Column5
abc def ghi
mno pqr
......这是我用来打印这些值的代码:
try {
FileInputStream inputStr = new FileInputStream(fileName);
XSSFWorkbook xssfWork = new XSSFWorkbook(inputStr) ;
XSSFSheet sheet1 = xssfWork.getSheetAt(0);
Iterator rowItr = sheet1.rowIterator();
while ( rowItr.hasNext() ) {
XSSFRow row = (XSSFRow) rowItr.next();
System.out.println("ROW:-->");
Iterator cellItr = row.cellIterator();
while ( cellItr.hasNext() ) {
XSSFCell cell = (XSSFCell) cellItr.next();
System.out.println("CELL:-->"+cell.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}此代码生成的输出为:-
ROW:-->
CELL:-->Column1
CELL:-->Column2
CELL:-->Column3
CELL:-->Column4
CELL:-->Column5
ROW:-->
CELL:-->abc
CELL:-->def
CELL:-->ghi
ROW:-->
CELL:-->mno
CELL:-->pqr因此,如果我们查看上面的输出,我们可以注意到POI库没有选取我留下空值的单元格,有没有一种方法可以将这些值作为null。或者是一种识别显示的值跳过了空白单元格的方法?
谢谢。
发布于 2020-12-01 05:49:03
for (Row row: sheet){
// This will return null if cell is empty / blank
Cell cell = row.getCell(columnNumber);
}https://stackoverflow.com/questions/4929646
复制相似问题