poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amol Deshmukh <adeshm...@hobsons-us.com>
Subject RE: columns not in their original order (XLS)
Date Mon, 07 Feb 2005 13:16:29 GMT
you may want to try something along the lines of:



for (int i=sheet.getFirstRowNum(); i<sheet.getLastRowNum(); i++) {
    row = sheet.getRow(i);
    // do somethign with row
}




HTH,
~ amol

-----Original Message-----
From: Angel Todorov [mailto:attodorov@gmail.com]
Sent: Monday, February 07, 2005 6:59 AM
To: poi-user@jakarta.apache.org
Subject: columns not in their original order (XLS)


Hello !

I have a question regarding parsing XLS files - whenever i try to
traverse an HSSFSheet using an iterator and obtaining HSSFRow objects,
i get the row elements in a completely messed up way - not as if they
are in the XLS sheet:

for example, if i have a table like that:

colname1 | colname2 | colname 3
----------------------------------------------------
  test1      |     test2    |     test3
----------------------------------------------------

i get that:

colname3 | colname1 | colname2
----------------------------------------------------
test2        |     test1    |     test3
---------------------------------------------------

the row elements , for each separate row, are also ordered in a
completely "random" order.

I am using the following code for that:

<CODE>

try {

			while (iter.hasNext())
			{
				HSSFRow row = (HSSFRow)iter.next();
				Iterator celli = row.cellIterator();

				//new row Vector Data
				Vector rowData = new Vector();
				while (celli.hasNext())
				{
					HSSFCell cell =
(HSSFCell)celli.next();

					switch (cell.getCellType())
					{
						case
HSSFCell.CELL_TYPE_NUMERIC:
							rowData.add(new
Double(cell.getNumericCellValue()));
							break;
						case
HSSFCell.CELL_TYPE_STRING:
	
rowData.add(cell.getStringCellValue());
							break;
						case
HSSFCell.CELL_TYPE_BLANK:
							rowData.add(" ");
							
					}
				}
				report.add(rowData);
			}

</CODE>

I don't think that java's Vector is a data structure which doesn't
preserve the order of adding elements. So I should be probably doing
something wrong with the HSSF API. Thank you very much in advance.

Regards,
Angel

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


Mime
View raw message