简体   繁体   中英

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.

嗯,这可能有点愚蠢(也许我没有得到物理行和逻辑行之间的区别),但是

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM