从 MVC C# 导出到 excel 后如何以日期时间格式显示日期

How can I display the date in datetime format after exporting from MVC C# to excel

我正在使用 EPPlus 库从 sql table 中读取日期时间值并将其导出到 excel。导出工作正常,但是当我查看 excel 文件时,日期显示为双精度而不是 dateime 我将我的代码放在下面

workSheet.Row(1).Height = 20;
workSheet.Row(1).Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
workSheet.Row(1).Style.Font.Bold = true;

workSheet.Cells[1, 1].Value = "UploadId";
workSheet.Cells[1, 2].Value = "ClientId";
workSheet.Cells[1, 3].Value = "Email1";
workSheet.Cells[1, 4].Value = "Email2";
workSheet.Cells[1, 5].Value = "Email3";
workSheet.Cells[1, 6].Value = "Email4";
workSheet.Cells[1, 7].Value = "DateStamp";


//Body of table  
//  
int recordIndex = 2;
foreach (var exportData in dataToExport)
{
    //double date = double.Parse(date);
    //string sDate = (workSheet.Cells[recordIndex, 7]).Value.ToString();
    //double date = double.Parse(sDate);
    //var dateTime = DateTime.FromOADate(date).ToString("MMMM dd, yyyy");
    workSheet.Cells[recordIndex, 1].Value = UploadId;
    workSheet.Cells[recordIndex, 2].Value = exportData.ClientId;
    workSheet.Cells[recordIndex, 3].Value = exportData.Email1;
    workSheet.Cells[recordIndex, 4].Value = exportData.Email2;
    workSheet.Cells[recordIndex, 5].Value = exportData.Email3;
    workSheet.Cells[recordIndex, 6].Value = exportData.Email4;
    workSheet.Cells[recordIndex, 7].Value = exportData.DateStamp;             
    recordIndex++;
}

应该这样做;

workSheet.Cells[recordindex, 7].Style.Numberformat.Format = "yyyy-MM-dd";