title: Java Apache POI Blank Cells
body: <p>I am new to Apache POI but not new to Java. I been trying to convert data from one excel file to another, changing any delimiter data to new cells. Although most of the new data is correct but a few exceptions are not following the rules for blank cells.
  Here is the input file <a href="https://ufile.io/bce15" rel="nofollow noreferrer">https://ufile.io/bce15</a>
  and here is the output file <a href="https://ufile.io/55020" rel="nofollow noreferrer">https://ufile.io/55020</a></p>
  
  <p>In the Image below record 4 and 5 are not playing by the rules, and i cant figure out why!!</p>
  
  <p><a href="https://i.stack.imgur.com/0WgIo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0WgIo.png" alt="enter image description here"></a></p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.Iterator;
  
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  
  
  public class testWrite {
  public static void main( String [] args ) {             
      int rowNums = 1;
      try {
  
          FileInputStream file = new FileInputStream(new      File("ExceptionDataDummy.xlsx"));;
          XSSFWorkbook wb = new XSSFWorkbook(file);
          XSSFSheet sheet = wb.getSheetAt(0);           
          String filename = "ExceptionDataResult.xlsx" ;
          XSSFWorkbook workbook = new XSSFWorkbook();
          XSSFSheet sheet1 = workbook.createSheet("FirstSheet");             
          Iterator&lt;Row&gt; rows = sheet.rowIterator();            
          int col = 0;
          while( rows.hasNext() ) {  
              XSSFRow row = (XSSFRow) rows.next();
              XSSFRow row1 = sheet1.createRow((short)rowNums);
              System.out.println("\n");
              Iterator&lt;Cell&gt; cells = row.cellIterator();
              while( cells.hasNext() ) {
  
                  XSSFCell cell = (XSSFCell) cells.next();
                  if(XSSFCell.CELL_TYPE_NUMERIC==cell.getCellType()) {                        
                      row1.createCell(col).setCellValue(cell.getNumericCellValue());
                      col++;                   
                  }
                  else
                  if(XSSFCell.CELL_TYPE_STRING==cell.getCellType()){
                      String contents =  cell.getStringCellValue();
                      String[] items = contents.split(",");                       
                      for (String item : items) {                         
                          row1.createCell(col).setCellValue(item);
                          col++;                          
                      }
                  }
                  else
                      if(XSSFCell.CELL_TYPE_BOOLEAN==cell.getCellType()) {
                          row1.createCell(col).setCellValue(cell.getBooleanCellValue());
                          col++;                          
                      }
                      else
                          if((cell.equals("")) || (XSSFCell.CELL_TYPE_BLANK==cell.getCellType()) || (cell == null)) {
  
                              cell.setCellType(Cell.CELL_TYPE_BLANK);
                              col++;                              
                          }
                              else {                                  
                         System.out.print("Unknown cell type");
                              }
              }
              rowNums++;
              col=0;               
          }
          FileOutputStream fileOut = new FileOutputStream(filename);
          workbook.write(fileOut);
          fileOut.close();
          System.out.println("Your excel file has been generated!");
          wb.close();
          workbook.close();
      } catch ( IOException ex ) {
          ex.printStackTrace();
      }                   
  }
  }
  </code></pre>