[英]Count excel rows from specific index to last row - Apache POI
for (int i = 0; i < loc1.workbook.getNumberOfSheets(); i++) {
if (loc2.workbook.getNumberOfSheets() <= i) return;
loc1.sheet = loc1.workbook.getSheetAt(i);
loc2.sheet = loc2.workbook.getSheetAt(i);
int num1 = loc1.sheet.getPhysicalNumberOfRows();
int num2 = loc2.sheet.getPhysicalNumberOfRows();
}
How do I count the no.我如何计算没有。 of rows starting from a specific index?从特定索引开始的行数? The above code counts the total no.上面的代码计算总数。 of rows.行。 loc1 and loc2 are ref variable of the class containing workbook, sheet, row, and cell variable. loc1 和 loc2 是包含工作簿、工作表、行和单元格变量的类的引用变量。
嗯,这可能有点愚蠢(也许我没有得到物理行和逻辑行之间的区别),但是
getPhysicalNumberOfRows() - specific_index;
You can use an Iterator to read the row.您可以使用迭代器来读取行。
int indexStart = 1;
Iterator<Row> rows = sheet.rowIterator();
while ( rows.hasNext() ) {
Row row = rows.next();
if( row.getRowNum() < indexStart ) {
continue;
}
// your code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.