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]

  • ... Swati, Singhal (IE10)
    • ... "Нина Маслов"
    • ... Swati, Singhal (IE10)
      • ... Avik Sengupta
    • ... Nichole_L_Smith
    • ... Swati, Singhal (IE10)
      • ... "Нина Маслов"
    • ... Umaa Rebbapragada
    • ... Swati, Singhal (IE10)
    • ... Swati, Singhal (IE10)

Reply via email to