110,545
社区成员
发帖
与我相关
我的任务
分享
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();
}
//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();