title: Detect datatable date field and force date format in EPPlus export
body: <p>I have a button on my page that when clicked exports data from a gridview to excel.</p>
  
  <pre><code>protected void btExport_Click(object sender, EventArgs e)
  {
      Response.Clear();
      Response.Charset = "";
      Response.ContentEncoding = System.Text.Encoding.UTF8;
      Response.Cache.SetCacheability(HttpCacheability.NoCache);
      Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      Response.AddHeader("content-disposition", "attachment;filename=Output.xlsx");
  
      DataTable dt= gvOutput.DataSource as DataTable;
  
      ExcelPackage pck = new ExcelPackage();
      using(pck)
      {
        ExcelWorksheet wsDt = pck.Workbook.Worksheets.Add("Sheet1");
        wsDt.Cells["A1"].LoadFromDataTable(dt, true, TableStyles.None);
        wsDt.Cells[wsDt.Dimension.Address].AutoFitColumns();
  
        Response.BinaryWrite(pck.GetAsByteArray());
  
      }
  
      Response.Flush();
      Response.End();
  }
  </code></pre>
  
  <p>This is working fine using the above code, however date fields are formatted as integers. I understand specific cells can be forced to have a certain format, but my issue is that the date columns will change as the dataset for the gridview is dynamic.</p>
  
  <p>I need a way to identify on the fly which column is a date and to force the format of that column to be a date time.</p>
  
  <p>I imagine it will involve an IF statement like this but I haven't got a clue what to put in it or where to put it!</p>
  
  <pre><code>if (dt.Columns[x].DataType == typeof(DateTime))
  { 
      //do something
  }
  </code></pre>
  
  <p>Any ideas/help is greatly appreciated.</p>