I have a excel sheet with data in 200 columns, to import in to DB i'm using below code
private File upp;
InputStream input = new FileInputStream(upp);
POIFSFileSystem fs = new POIFSFileSystem(input);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while(rows.hasNext()) {
String data="";
HSSFRow row = (HSSFRow) rows.next();
if(row.getRowNum() == 0 || row.getRowNum() == 1) {
Iterator rowCells = row.cellIterator();
while(rowCells.hasNext()) {
HSSFCell cell = (HSSFCell) rowCells.next();
for(int i=0; i <= cell.getCellNum(); i++) {
}
data = data + cell.getCellNum() + " ,";
}
System.out.println(data);
}
slrow++;
}
i'm excepting output to be
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,
but the output is
0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,17 ,16 ,18 ,
its not reading in sequential order as expected I'm unable to find out where the mistake is in this code
HSSFCell.getCellNum()is deprecated since a long time. UsegetColumnIndex(). - Axel Richter