Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friend I want your help.I am reading an excel file & writing data to access database it is writting correctly but if there is any blank space in excell sheet it is reading the next row & puting insted of blank data so next cell comes to balnk data cell.my code is like this
Java
Sheet mySheet = myWorkBook.getSheetAt(0);

       /** We now need something to iterate through the cells.**/
       Iterator rowIter = mySheet.rowIterator();

         while(rowIter.hasNext())
         {
             Row myRow = (XSSFRow) rowIter.next();
             Iterator cellIter = myRow.cellIterator();
             Vector cellStoreVector=new Vector();
             String nextElement="";

             while(cellIter.hasNext())
             {
                 Cell myCell = (XSSFCell) cellIter.next();
                 System.out.println("Cell Type is :"+myCell.getCellType()+" | "+myCell.toString());

                 if(myCell.getCellType()==XSSFCell.CELL_TYPE_BLANK)
                 {
                     System.out.println("Blank data found ");
                     myCell.setCellValue("-");
                     cellStoreVector.addElement(myCell);
                 }
                 else
                 {
                 cellStoreVector.addElement(myCell);

                 }
             }
             System.out.println("");
             cellVectorHolder.addElement(cellStoreVector);
         }
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }

I have used XSSFCell.CELL_TYPE_BLANK but it is not going to this loop please help me.Thanks.
Posted

1 solution

Just check the cell string value:
Java
        if(""+myCell.toString()=="")
{
    System.out.println("Blank data found ");
    myCell.setCellValue("-");
    cellStoreVector.addElement(myCell);
}
else
{
cellStoreVector.addElement(myCell);

}
 
Share this answer
 
Comments
maheshpardeshi 20-Sep-12 8:17am    
hi Mehdi I have check it before but it is not workin actually what happning is that when we read excel file in Cell myCell = (XSSFCell) cellIter.next(); allready next rows data comes in stead of blank data of that cell so those we check if(""+myCell.toString()=="")
it does not goes in that loop becse all ready data of next row is there if blank cell comes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900