Reputation: 11
While reading data from excel file, we can use
no_of_rows = sheet.getPhysicalNumberOfRows();
to get the number of rows having data. Is there a way to get the count of rows having data in the first column of the sheet?
Upvotes: 0
Views: 86
Reputation: 708
there not any method to get no of rows for particular column in apache poi. you manually need to traverse the row each one by one and then you can get it.
to get row count for particular column you can refer to this link
Upvotes: 1
Reputation: 137
Have every column different row number?
int rows; // No of rows rows = sheet.getPhysicalNumberOfRows();
int cols = 0; // No of columns
int tmp = 0;
for (int i = 0; i < rows; i++) {
row = sheet.getRow(i);
if (row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if (tmp > cols) {
cols = tmp;
}
}
}
if (cols == 23) {
row = sheet.getRow(0);
if ("I.D.Number".equals(row.getCell(0).toString())) {
if ("Name".equals(row.getCell(1).toString())) {
if ("Surname".equals(row.getCell(2).toString())) {
applicaple = true;
}
}
}
}
Iterator rowsExcel = sheet.rowIterator();
XSSFRow row2 = null;
if (uygunluk == true) {
while (rowsExcel.hasNext()) {
row2 = (XSSFRow) rowsExcel.next();
if (row2.getRowNum() != 0) {
if (fmt.formatCellValue(row2.getCell(0)) == null || (fmt.formatCellValue(row2.getCell(0)).trim().equalsIgnoreCase(""))) {
System.out.print.ln("warn!!");
return;
} else if (fmt.formatCellValue(row2.getCell(0)) != null || !(fmt.formatCellValue(row2.getCell(0)).trim().equalsIgnoreCase(""))) {
idInfo = fmt.formatCellValue(row2.getCell(0);
}
Upvotes: 0