poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl-Heinz Zengerle" <karl-heinz.zenge...@sawag.com>
Subject AW: reading cells question
Date Mon, 03 May 2004 14:57:38 GMT
Hi Henry.

Read the thread "Phantom cells?" and I hope several things become
clearer then.

Regards,	Karl-Heinz.


-----Urspr√ľngliche Nachricht-----
Von: news [mailto:news@sea.gmane.org] Im Auftrag von henry n
Gesendet: Freitag, 30. April 2004 18:54
An: poi-user@jakarta.apache.org
Betreff: reading cells question

This question is very similar to one just asked, but I am still not
finding an
answer

I have an excel file with 20 columns, all columns are formatted as
'general'. I
only want to extract data out of columns 2, 3, 4, 5 and 19 (zeo-based
cell count
so cell 19 is the twentieth cell). My problem is that cells 0 or 1 are
sometimes
empty.

So if I do a row.getFirstCellNum() I will get either a 0 or a 1. How do
I know
if I am extracting from cells 2,3,4,5 or 19? If I do a
row.getLastCellNum() I
always get 20.

This is what I want to do:

private String[] getRowValues(HSSFRow aRow) {
	String[] cells = new String[5];

	/*
	 * hard coded for 20 cells - only want cells 2,3,4,5,19
	 * 1st cell is index 0, last cell is index 19
	 * KEY:
	 * 2: country
	 * 3: long filename
	 * 4: short filename (with .HTM extension)
	 * 5: date (string)
	 * 19: excel file inclusion indicator 0==no, 1==yes
	 */
	
         for (int i = 0; i < 20; i++) {
				
	    if ((i == 2) || (i == 3)  || (i == 4)  || (i == 5)  || (i ==
19)) {

	       HSSFCell cell = aRow.getCell((short)i);
					
		//error-check
		if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK)
		   cells[i] = "bllank: "+i;
		else if (cell.getCellType() == HSSFCell.CELL_TYPE_ERROR)
		   cells[i] = "column: "+i+"error value:
"+cell.getErrorCellValue();
		else if (cell.getCellType() ==
HSSFCell.CELL_TYPE_STRING)
		   cells[i] = cell.getStringCellValue();
		else if (cell.getCellType() ==
HSSFCell.CELL_TYPE_NUMERIC)				   cells[i] =
new Double(cell.getNumericCellValue()).toString();
					
	   } //end check for important cells

       } //end loop through 20 cells

       return cells;

} //end getRowValues


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


Mime
View raw message