title: POI : How to get the correct Cell Type of a formatted cell
body: <p>I have one formatted cell in excel as <em>dd-mm-yyyy hh:mm:ss</em> .(Right Click on a cell > Select Format Cells >Select Custom and  Select mentioned format)When I am trying to get the cell Type of this cell using cell.getCellType(),I am getting it as String. This is Similar for the cell which is formatted as Number. Is it possible to get the  cell Type as Cell.CELL_TYPE_NUMERIC for the formatted cell in excel as dd-mm-yyyy hh:mm:ss using Apache POI? OR How I need to format the cell so that I can get cell Type as Cell.CELL_TYPE_NUMERIC.</p>
  
  <p>When using jxl I am getting the CellType of that Cell as DateFormulae.</p>
  
  <p>EDIT :
  Below is the code I am using.In cell , we are sending Date value which is taken as Numeric cell type in POI. But it is taking that value as String.</p>
  
  <pre><code>private void copyCell(Cell cell,Row row, int targetRow, Sheet sheet) {
  
      // Copy style from old cell and apply to new cell
      CellStyle newCellStyle = newWorkbook.createCellStyle();
      newCellStyle.cloneStyleFrom(cell.getCellStyle()); 
  
      // If there is a cell comment, copy
      if(cell==null){
          newCell.setCellValue("");
          return;
      }
      if (cell.getCellComment() != null) newCell.setCellComment(cell.getCellComment());
  
      // If there is a cell hyperlink, copy
      if (cell.getHyperlink() != null) {newCell.setHyperlink(cell.getHyperlink()); 
      }
      // Set the cell data type
      newCell.setCellType(cell.getCellType());
  
      // Set the cell data value
  
      switch (cell.getCellType())
      {
      case Cell.CELL_TYPE_BLANK:
          newCell.setCellValue(cell.getStringCellValue());
          newCell.setCellStyle(newCellStyle);
          newCell.setCellType(3);
          break;
      case Cell.CELL_TYPE_BOOLEAN:
          newCell.setCellValue(cell.getBooleanCellValue());
          newCell.setCellStyle(newCellStyle);
          newCell.setCellType(4);
          break;
      case Cell.CELL_TYPE_ERROR:
          newCell.setCellErrorValue(cell.getErrorCellValue());
          newCell.setCellStyle(newCellStyle);
          newCell.setCellType(5);
          break;
  
      case Cell.CELL_TYPE_NUMERIC:
          if(DateUtil.isCellDateFormatted(cell)){
              newCell.setCellValue(cell.getDateCellValue());
          }else{
              DataFormatter dataFormatter=new DataFormatter();
              Format format=dataFormatter.getDefaultFormat(cell);
              dataFormatter.setDefaultNumberFormat(format);
  
              newCell.setCellValue(dataFormatter.formatCellValue(newCell)); 
          }
          newCell.setCellType(0);
          break;
      case Cell.CELL_TYPE_STRING:
          if(DateUtil.isCellDateFormatted(cell)){
  
          }
          newCell.setCellValue(cell.getStringCellValue());
  
  
          newCell.setCellStyle(newCellStyle);
          newCell.setCellType(1);
          break;
  
      }
  
  }
  </code></pre>
  
  <p>EDIT 2:
  @Gagravarr- <a href="https://stackoverflow.com/questions/10616935/reading-date-value-from-excel-cell-as-a-string">Reading date value from excel cell as a String</a> is not resolving my problem.
  My Query is :: Based on the cellType of a cell I have to perform some operation.But when I am reading a date or number cell,I am getting the cellType as String.Since I am getting the cellType as String I am not in a position to apply the operations that I need to apply for date or numeric one.</p>
  
  <p>Say for Example : If my cell is of Date type then I will set the value of that cell as today's date.I tried to do the operations in String Cell Type case like :</p>
  
  <pre><code>if(DateUtil.isCellDateFormatted(cell)){}
  </code></pre>
  
  <p>But I am getting error:Cannot get a numeric value from a text cell.
  Thanks in Advance.</p>