使用下面代码导出EXCEL文件后,文件日期部分为数字,如何将日期设置成日期格式啊            DirectoryInfo outputDir = new DirectoryInfo("d:\abc\");            FileInfo newFile = new FileInfo(outputDir.FullName + strTargetExcel + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx");            using (ExcelPackage pck = new ExcelPackage(newFile))
            {
                ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Accounts");
                ws.Cells["A1"].LoadFromDataTable(dt, true);
                pck.Save();
            }

解决方案 »

  1.   

    参见:https://stackoverflow.com/questions/22832423/excel-date-format-using-epplus
      

  2.   

    官方示例文档有这方面的代码:
                //Load the datatable and set the number formats...
                wsDt.Cells["A1"].LoadFromDataTable(dt, true, TableStyles.Medium9);
                wsDt.Cells[2, 2, dt.Rows.Count + 1, 2].Style.Numberformat.Format = "#,##0";
                wsDt.Cells[2, 3, dt.Rows.Count + 1, 4].Style.Numberformat.Format = "mm-dd-yy";
                wsDt.Cells[wsDt.Dimension.Address].AutoFitColumns();