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: [EMAIL PROTECTED]
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: '[EMAIL PROTECTED]'
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]