Click here to Skip to main content
12,299,947 members (53,146 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Java
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
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 19-Sep-12 22:21pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Just check the cell string value:
        if(""+myCell.toString()=="")
{
    System.out.println("Blank data found ");
    myCell.setCellValue("-");
    cellStoreVector.addElement(myCell);
}
else
{
cellStoreVector.addElement(myCell);
 
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100