我正在使用EPPlus库从sql表中读取日期时间值,并将其导出到excel。导出工作正常,但是当我查看excel文件时,日期显示为双倍而不是日期,我将代码放在了下面
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";