I have an excel file which contains various information and also contains a table structure which has two headers unit code and description.So now i am able to read the whole excel file using POI,but my problem is that i need to read only the two values of the coloumns of the table in excel.But i am not able to properly doing that,Here is my code what i have done so far.
public class ReadExcelFileToList {
public static void main(String[] args) throws IOException {
InputStream input = null;
try {
input = new FileInputStream(
"C:\\Users\\jeet.chatterjee\\Downloads\\unitUploadFormat.xlsx");
System.out.println("file is found");
XSSFWorkbook wb = new XSSFWorkbook(input);
XSSFSheet sheet = wb.getSheetAt(0);
int rowCount = 0;
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
XSSFRow row = (XSSFRow) rows.next();
System.out.println("\n");
if (rowCount == 3) {
Iterator cells = row.cellIterator();
while (cells.hasNext()) {
XSSFCell cell = (XSSFCell) cells.next();
if (XSSFCell.CELL_TYPE_STRING == cell.getCellType())
System.out.print(cell.getStringCellValue()
+ " ");
/*
* else if (XSSFCell.CELL_TYPE_STRING ==
* cell.getCellType())
* System.out.print(cell.getStringCellValue() +
* " "); else if (XSSFCell.CELL_TYPE_STRING ==
* cell.getCellType())
* System.out.print(cell.getStringCellValue() +
* " ");
*/
else
System.out.print("Unknown cell type");
}
rowCount++;
}
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
input.close();
}
}
}
i am using sheet.getLastRowNum() to get my desired result,But i am not getting it somebody please help.. This is my excel file i just want to get kg & kilogram values and so on ,all the items which will be putted there will be extrated.