Reputation: 13
I want to read data in specific row and print it using Apache POI. Example: I want to print row = 4 in an excel file and row # will keep changing.
Iterator<Row> rowIterator = sheet.iterator();
rowData = new ArrayList<>();
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()){
Cell cell = cellIterator.next();
System.out.println("Col Index = "+cell.getColumnIndex());
System.out.println("Col Index = "+cell.getStringCellValue());
}
I tried above code and it is giving me 1st row in excel but I want specific row from excel.
Upvotes: 0
Views: 324
Reputation: 5709
Something like this?
Row row = sheet.getRow(4);
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()){
Cell cell = cellIterator.next();
System.out.println("Col Index = "+cell.getColumnIndex());
System.out.println("Col Index = "+cell.getStringCellValue());
}
Upvotes: 1