如何获得使用java的Excel中选定的行的数量?
我想要列出设备ID的选定行数,忽略使用Java的空白单元格。 我正在使用Apache POI来处理Excel自动化的Excel表格。
计数应从第3行(即LV431408)开始,直到第17行(即A9N26924)。
我使用sheet.getPhysicalNumberofRows(),但它考虑空白单元格。
请参阅附件的截图。
你应该使用下面的代码来获得总排除空白。
int count = 0; for (Row row : sheet) { for (Cell cell : row) { if (cell.getCellType() != Cell.CELL_TYPE_BLANK) { if (cell.getCellType() != Cell.CELL_TYPE_STRING || cell.getStringCellValue().trim().length() > 0) { count++; break; } } } }