poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Swati, Singhal (IE10)" <Swati.Sing...@honeywell.com>
Subject RE: Reading excel file with blanks
Date Wed, 15 Oct 2003 14:13:38 GMT
thanx!!!
Just tried it...seems to work!
Thanx

-----Original Message-----
From: Umaa Rebbapragada [mailto:Umaa.Rebbapragada@cnet.com]
Sent: Wednesday, October 15, 2003 7:34 PM
To: 'poi-user@jakarta.apache.org '
Subject: RE: Reading excel file with blanks


Swati, 

You first need to create a cell in this position.  Right now, you're
calling setCellType and setCellValue on a null object.  That is causing
your NPE.

add

row.createCell((short)j);

That should fix.

ur

-----Original Message-----
From: Swati, Singhal (IE10)
To: poi-user@jakarta.apache.org
Sent: 10/15/2003 9:58 AM
Subject: RE: Reading excel file with blanks

ok,
I am reading an excel file, but everytime it encounters a blank cell, it
returns null.

Please see the code below: I check if cell if null & try setting the
cell
type to a String with a null string value.
But it throws a nullPointer exception.
Please help!!

for(int j=0;j<maxColumnSize;j++)
{
	HSSFCell cell = row.getCell((short)j);
	if(cell==null)
	{
   		System.out.println("Cell Value is Null");	
	//	cell.setCellType(cell.CELL_TYPE_STRING);
	//	cell.setCellValue("");
		System.out.println("Cell
VALUE:"+cell.getStringCellValue());
	//	dataArrList.add(cell.getStringCellValue());

    	}	
    	else
    	{
		cell_type = cell.getCellType();
		switch(cell_type)
		{
			case 0: double dDataValue =
cell.getNumericCellValue();
				  Double dblVal = new
Double(dDataValue);
				  String dsValue = dblVal.toString();
				  dataArrList.add(dsValue);
				  break;
			    		
	  		case 1: String sDataValue =
cell.getStringCellValue();
				  dataArrList.add(sDataValue);
				  break;
	

	  		case 3: System.out.println("Cell is BLANK with
Value:"+cell.CELL_TYPE_BLANK);		
				  String blnkValue =
cell.getStringCellValue();
	
System.out.println("blnkValue:"+blnkValue);
				  if(blnkValue==null)
				  {
						System.out.println("Cell
Value is Null");	
	
cell.setCellType(cell.CELL_TYPE_STRING);
cell.setCellValue("");
	
System.out.println("blank
value:"+blnkValue);
	
dataArrList.add(blnkValue);

				}	
				break;
				    		
			case 4:boolean bDataValue =
cell.getBooleanCellValue();
				 Boolean boolVal = new
Boolean(bDataValue);
				 String bValue = boolVal.toString();
				 dataArrList.add(bValue);
				 break;		
		}		 		   
    	}	
}



-----Original Message-----
From: Swati, Singhal (IE10) 
Sent: Wednesday, October 15, 2003 6:40 PM
To: 'poi-user@jakarta.apache.org'
Subject: Reading excel file with blanks
Importance: High


Hi,

I am using POI in one of my projects.

I am having trouble reading an excel file which contains some blank
cells.
Has anyone ever read an excel file which may contain few blank cells??
How do we fix that??

Please help!!

Thanks

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