Help with POI HSSF

I am trying to read a excel file by using HSSF API. It is not reading file in correct order of cells ;Below is my code:

class TestExcel{

HSSFWorkbook wb;

HSSFSheet sheet;

HSSFRow row;

HSSFCell cell;

int k=0;

java.util.Iterator iter,iter1;

FileInputStream file;

int i=0,j=0;

@SuppressWarnings("deprecation") TestExcel(){

try{

file=new FileInputStream("C:/ReportFormat/test.xls");

//file=new FileInputStream("C:/Documents and Settings/user/Desktop/excel/DCB OCTOBER 2006-CSC.xls");

}

catch(FileNotFoundException fnf){

fnf.printStackTrace();

}

try{

wb =new HSSFWorkbook(file);

}

catch(IOException ioe){

ioe.printStackTrace();

}

for(i=0;i<wb.getNumberOfSheets();i++){

sheet=wb.getSheetAt(i);

iter=sheet.rowIterator();

while(iter.hasNext()){

row=(HSSFRow)iter.next();

iter1=row.cellIterator();

while(iter1.hasNext()){

cell=(HSSFCell)iter1.next();

if(cell.getCellType()==HSSFCell.CELL_TYPE_STRING){

System.out.println("The value is :"+cell.getStringCellValue().toString());

}

if(cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC){

System.out.println("The numeric value is :"+cell.getNumericCellValue());

}

if(cell.getCellType()==HSSFCell.CELL_TYPE_FORMULA){

System.out.println("The formula is :"+cell.getCellFormula());

}

}

}

}

}

publicstaticvoid main(String args[]){

TestExcel obj=new TestExcel();

}

}

The input is :

First Sheet: First row :First cell=Title

2 nd Row :1 st cell=Column1

2 nd Row :2nd cell=Column2

2nd Row :3rd cell=Column3

2 nd Row :4th cell=Column4

Expected O/p is:

Title

Column1

Column2

Column3

Column4

But output got is:

Title

Column3

Column2

Column1

Column4

Let me know what I should modify so as to read the cells correctly.>

[3520 byte] By [sruthim] at [2007-11-26 12:15:48]
# 1
Hey , I did a work around for that; instead of getting the details into iterator I am directly iterating the row object using for loop.This is giving me the desired output,but the right way .So any body let me know how to do it using iterators?
sruthim at 2007-7-7 14:51:01 > top of Java-index,Archived Forums,Socket Programming...
# 2
This has nothing to do with Reflection & Reference Objects and not much to do with general Java programming either. Please find an HSSF forum and continue the discussion there.
ejp at 2007-7-7 14:51:01 > top of Java-index,Archived Forums,Socket Programming...