我有一个应用程序可以读取 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++);
}
关于java - 如何使用 apache poi 开始循环中的特定单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43481804/