如何开始使用apache poi循环中的特定单元格?

我有一个应用程序,读取一个Excel并获取信息。 这是我的代码,它读取列0和列1的信息。我想知道一种方法,只在行号34开始,从33跳过行1。

File file = new File(inFileName); Workbook workBook = WorkbookFactory.create(file); Sheet sheet = workBook.getSheetAt(0); Iterator<Row> rowIter = sheet.rowIterator(); while(rowIter.hasNext()){ Row myRow =rowIter.next(); Cell cell1 = myRow.getCell(0); Cell cell2 = myRow.getCell(1); ... Iterator<Cell> cellIter = myRow.cellIterator(); while(cellIter.hasNext()){ Cell myCell = cellIter.next(); } //bd.addAnimalls(cell1.toString(),cell2.toString()); Toast.makeText(getApplicationContext(), "on inserting", Toast.LENGTH_SHORT).show(); } 

您可以使用sheet.getRow(rowNum)获取特定的行。

所以你的代码可以改成这样:

 File file = new File(inFileName); Workbook workBook = WorkbookFactory.create(file); Sheet sheet = workBook.getSheetAt(0); int rowCtr = 33; Row myRow = sheet.getRow(rowCtr++); while (myRow != null) { Cell cell1 = myRow.getCell(0); // rest of your loop code myRow = sheet.getRow(rowCtr++); }