title: How to correctly format a date cell and populate content using Apache POI 3.7
body: <p><strong>Background:</strong></p>
  
  <p>I need to export a spreadsheet document with one column containing date formatted data.</p>
  
  <p>I'm currently setting up the workbook style like so:</p>
  
  <pre><code>...
  dateTimeStyle = workbook.createCellStyle();
  //dateTimeStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
  dateTimeStyle.setDataFormat((short)0x16);
  ...
  </code></pre>
  
  <p>and inserting the data into the cell/setting the format of the cell like so:</p>
  
  <pre><code>...    
  if (Date.class.isAssignableFrom(o.getClass())) {
  
      Calendar cal = Calendar.getInstance();
      cal.setTime((Date) o);
      cell.setCellStyle(dateTimeStyle);
      cell.setCellValue(cal);
  }
  ...
  </code></pre>
  
  <p><strong><em>Note:</strong> According to BuiltinFormats documentation (<a href="http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html" rel="nofollow noreferrer">http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html</a>) 0x16 refers to the date format I'm trying to achieve.</em></p>
  
  <p>The problem I have is that when I open the exported document in Microsoft Office Excel 2007, when I right-click the cell and choose <em>Format cells...</em> it shows the selected cell as having a custom format of dd/mm/yyyy hh:mm</p>
  
  <p><img src="https://i.stack.imgur.com/12H7V.png" alt="enter image description here"></p>
  
  <p>Also, VLOOKUP operations do not work on the column (which I may, admittedly, be doing wrong):</p>
  
  <p><img src="https://i.stack.imgur.com/jSOls.png" alt="enter image description here"></p>
  
  <p>I have a feeling this is due to a misunderstanding of how Excel stores and formats content, and would appreciate any help provided.</p>
  
  <p><strong>Question:</strong></p>
  
  <p>So, how do I correctly format/populate the cell so that Microsoft Excel treats it as a date and VLOOKUPs work etc?</p>
  
  <p><strong><em>Update:</strong> If I open the resulting file in Open Office Calc and choose Format Cells... the format shows up correctly as being Date. Starting to wonder, then, if this is an issue with the POI library and Excel 2007...</em></p>
  
  <p>Many thanks.</p>