最初我使用了4行数据然后我删除了最后两行。问题是,我仍然得到4作为总行数。我该怎么做以获得更新计数。
FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet firstSheet = (Sheet) workbook.getSheetAt(0);
System.out.println("No of rows:"+firstSheet.getPhysicalNumberOfRows());
Iterator<Row> iterator = firstSheet.iterator();
try{
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
cell.setCellType(Cell.CELL_TYPE_STRING);
if(!cell.getStringCellValue().isEmpty()){
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
writer.append(cell.getStringCellValue());
break;
}
}
}
}
}finally{
inputStream.close();
workbook.close();
writer.flush();
writer.close();
}
答案 0 :(得分:0)
通过删除Excel中的整行来清除该问题。如果要删除Excel中的某些数据,请不要清除单元格中的内容而是删除整行。