Click here to Skip to main content
Rate this: bad
good
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 23: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 at 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
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 BillWoodruff 108
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2014
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