if your cell object is null you can't do things like cell.getCellType on it. (you
should be getting a nullpointer exception there) i think in that case what you need to
do is create a new blank cell in the location.
-----Original Message-----
From: "Swati, Singhal (IE10)" <[EMAIL PROTECTED]>
To: POI Users List <[EMAIL PROTECTED]>
Date: Tue, 14 Oct 2003 01:03:55 -0700
Subject: Reading excel file with blanks
>
> Hi,
>
> I am using POI in one of my projects.
>
> I am having trouble reading an excel file which contains some blank cells.
> I read the excel sheet within a for loop cell by cell.
> But as soon as a blank cell is encountered, my program hangs. It stops
> processing the remaining blank cells.
>
> Please see the code below:
> Upon encountering a blank cell, it returns null. And i change the cell type
> to String. But it does not process the remaining cells.
>
> 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;
> }
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]