title: PHPExcel: how to set date format for a cell
body: <p>I need to save a date to Excel file, it must be output in format "dd/mm/yyyy" (or the local date format of the user), and to be treated as a date so a column of them could be sorted correctly.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;?php
  include_once("../PHPExcel/Classes/PHPExcel.php");
  date_default_timezone_set('Europe/London');
  $objPHPExcel = new PHPExcel();
  $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
  PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
  
  $objPHPExcel = new PHPExcel();
  $sheet = $objPHPExcel-&gt;getActiveSheet();
  PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
  
  //I didn't find dd/mm/yyyy format, so I used yyyy-mm-dd
  $sheet-&gt;setCellValueByColumnAndRow(0, 1, "2014-10-16");
  $sheet-&gt;getStyleByColumnAndRow(0, 1)
      -&gt;getNumberFormat()-&gt;setFormatCode(
          PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2
  );
  
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter-&gt;save("test.xlsx");
  </code></pre>
  
  <p>It creates a file, but instead of my local date format I see: "2014-10-16" and the format of the cell is "All formats" -> "yyyy-mm-dd". I wanted it to be parsed and output in my local date format.</p>
  
  <p>I looked into the source code of <code>PHPExcel/Classes/PHPExcel/Style/NumberFormat.php</code>, and found many date formats:</p>
  
  <pre><code>const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd';
  const FORMAT_DATE_YYYYMMDD = 'yy-mm-dd';
  const FORMAT_DATE_DDMMYYYY = 'dd/mm/yy';
  const FORMAT_DATE_DMYSLASH = 'd/m/y';
  const FORMAT_DATE_DMYMINUS = 'd-m-y';
  ...
  </code></pre>
  
  <p>But I am not sure what to use. How can I achieve the desired goal?</p>