The issue with the dates is because you need to format the date column on the sheet.
If you know which column is a date then you can just use the column index, but then your code is not as generic as it once was. The best idea would be to discover the date fields at run-tim:
public void ExportToExcel(System.Data.DataTable dt)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=myexcelfile.xlsx");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
var package = new ExcelPackage();
var sheet = package.Workbook.Worksheets.Add("My Data");
sheet.Cells["A1"].LoadFromDataTable(dt, true);
for(int x = 0; x < dt.Columns.count; x++)
{
if(dt.Columns[i].DataType==typeof(DateTime))
{
sheet.Column(x).Style.Numberformat.Format = "yyyy-mm-dd"
}
}
Response.BinaryWrite(package.GetAsByteArray());
Response.End();
}
I hope that help ^_^
Andy