You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by henry n <he...@ihsenergy.com> on 2004/04/30 18:54:16 UTC

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


AW: AW: AW: reading cells question

Posted by Karl-Heinz Zengerle <ka...@sawag.com>.
Fine.

It's also very fine that you could find all things in existing threads
and you needed just the pointer to them.

Regards,	Karl-Heinz.


-----Ursprüngliche Nachricht-----
Von: news [mailto:news@sea.gmane.org] Im Auftrag von henry noerdlinger
Gesendet: Dienstag, 4. Mai 2004 15:48
An: poi-user@jakarta.apache.org
Betreff: Re: AW: AW: reading cells question

Thanks!!!

Think I got it. I just needed to check if the cell was null. Can't 
believe I overlooked that.

Even got the date handling working now. Great stuff.

Peace,
-henry n



---------------------------------------------------------------------
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


Support for formula requiring operands from multiple sheets

Posted by Prasanna Jaganathan <pj...@orangescape.com>.
Hi

Does POI support formula like "Sum(Sheet1:Sheet4!A1)"??
The formula parser parses it to a RPN notation  "Sheet1!A1 SUM"
It is taken to be a Ref3DPtg. Is it a bug or a supported feature?
Are these kind called named ranges?

Thanks,
Prasanna.




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


Re: AW: AW: reading cells question

Posted by henry noerdlinger <he...@ihsenergy.com>.
Thanks!!!

Think I got it. I just needed to check if the cell was null. Can't 
believe I overlooked that.

Even got the date handling working now. Great stuff.

Peace,
-henry n



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


AW: AW: reading cells question

Posted by Karl-Heinz Zengerle <ka...@sawag.com>.
Hi Henry.

Look at
http://jakarta.apache.org/poi/hssf/how-to.html
read it exactly and there's a further link which contains that sample
HSSF class.

Regards,	Karl-Heinz.


-----Ursprüngliche Nachricht-----
Von: Karl-Heinz Zengerle [mailto:karl-heinz.zengerle@sawag.com] 
Gesendet: Dienstag, 4. Mai 2004 11:28
An: 'POI Users List'
Betreff: AW: AW: reading cells question

Hi Henry.

So you've found a lot of information with that hint.

The classes you need (if you're not interested in styles etc.) are
HSSFWorkbook, HSSFSheet, HSSFRow and HSSFCell.

Check whether a row is null and ignore it then and check whether a cell
is null and ignore it then.

For special date handling there are also several threads where you
immediately see what you've to do.

Regards,	Karl-Heinz.


-----Ursprüngliche Nachricht-----
Von: news [mailto:news@sea.gmane.org] Im Auftrag von henry noerdlinger
Gesendet: Montag, 3. Mai 2004 19:14
An: poi-user@jakarta.apache.org
Betreff: Re: AW: reading cells question

Thank you Karl,

So what I infer is that I need to go by the row and column numbers 
inside the record.

What poi packages or classes should I be looking at? Must I access the 
lower-level API structures?

Regards,
-henry n



---------------------------------------------------------------------
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


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


AW: AW: reading cells question

Posted by Karl-Heinz Zengerle <ka...@sawag.com>.
Hi Henry.

So you've found a lot of information with that hint.

The classes you need (if you're not interested in styles etc.) are
HSSFWorkbook, HSSFSheet, HSSFRow and HSSFCell.

Check whether a row is null and ignore it then and check whether a cell
is null and ignore it then.

For special date handling there are also several threads where you
immediately see what you've to do.

Regards,	Karl-Heinz.


-----Ursprüngliche Nachricht-----
Von: news [mailto:news@sea.gmane.org] Im Auftrag von henry noerdlinger
Gesendet: Montag, 3. Mai 2004 19:14
An: poi-user@jakarta.apache.org
Betreff: Re: AW: reading cells question

Thank you Karl,

So what I infer is that I need to go by the row and column numbers 
inside the record.

What poi packages or classes should I be looking at? Must I access the 
lower-level API structures?

Regards,
-henry n



---------------------------------------------------------------------
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


Re: AW: reading cells question

Posted by henry noerdlinger <he...@ihsenergy.com>.
Thank you Karl,

So what I infer is that I need to go by the row and column numbers 
inside the record.

What poi packages or classes should I be looking at? Must I access the 
lower-level API structures?

Regards,
-henry n



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


Re: Page Break

Posted by Pavan Guduru <pa...@yahoo.com>.
Can you tell me which class to look for ...


Danny Mui <da...@muibros.com> wrote:
there's page break logic as of 2.5

Pavan Guduru wrote:

> How to give manual page breaks through HSSF. Any patch or any source code written also would help me alot
> 
> 
> 
> Thanks
> 
> Pavan
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> Win a $20,000 Career Makeover at Yahoo! HotJobs 

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

		
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 

Re: Page Break

Posted by Danny Mui <da...@muibros.com>.
there's page break logic as of 2.5

Pavan Guduru wrote:

> How to give manual page breaks through HSSF. Any patch or any source code written also would help me alot
> 
>  
> 
> Thanks
> 
> Pavan
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> Win a $20,000 Career Makeover at Yahoo! HotJobs 

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


Page Break

Posted by Pavan Guduru <pa...@yahoo.com>.
How to give manual page breaks through HSSF. Any patch or any source code written also would help me alot

 

Thanks

Pavan


		
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 

AW: reading cells question

Posted by Karl-Heinz Zengerle <ka...@sawag.com>.
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