You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Нина Маслов <nm...@mail.ru> on 2003/10/16 09:13:28 UTC
Re[2]: Reading excel file with blanks
don't want to sound rude, but there was exact same question here yesterday (which was answered) ....
basically if your cell object is null you can't do cell.get...
you can either create a new cell in the location of this one, or ignore it. or if you need to add something to your dataArrList, just add an empty string to it, if the cell is null.
-----Original Message-----
From: "Swati, Singhal (IE10)" <Sw...@honeywell.com>
To: poi-user@jakarta.apache.org
Date: Wed, 15 Oct 2003 06:58:28 -0700
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