我从excel文件中读取并打印到控制台(暂时)。问题是我正在阅读的excel文件是由几个人编辑的,为了方便起见,他们将表扩展了数百行,因为它每天更新15次,Apache POI认为这是数据和结果最终印刷了数百行。我的代码如下。我以为if current.Row.iterator()== null会结束while循环吗?
while (iterator.hasNext()) {
Row currentRow = iterator.next();
Iterator<Cell> cellIterator = currentRow.iterator();
if (currentRow.iterator() == null) { // i thought this would exit the while loop?
return;
}
while (cellIterator.hasNext()) {
Cell currentCell = cellIterator.next();
if (currentCell.getCellTypeEnum() == CellType.STRING) { // todo: probably don't need the if/else if?
System.out.print(currentCell.getStringCellValue() + " ");
} else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
String currentCellAsString = dataFormatter.formatCellValue(currentCell);
System.out.print(currentCellAsString + " ");
}
}
System.out.println();
}