• 数据写入到Excel,模板样式复杂


    先整理好Excel模板,如:

    接下来在程序获取上面整理好的Excel模板并替换关键字就可以了public ActionResult SummaryStatistics()

    public ActionResult SummaryStatistics()
    {         Workbook workbook;
    using (var stream = System.IO.File.OpenRead(Server.MapPath("/Templates/Statistics/汇总表.xlsx"))) { workbook = new Workbook(stream); } //上半部分统计 workbook.Replace(string.Format("${0}$", "TrainOrgCount"), summaryLastMonth.TrainOrgCount); workbook.Replace(string.Format("${0}$", "TrainOrgThanLastMonth"), summaryLastMonth.TrainOrgThanLastMonth); workbook.Replace(string.Format("${0}$", "TrainCount"), summaryLastMonth.TrainCount); workbook.Replace(string.Format("${0}$", "TrainThanLastMonth"), summaryLastMonth.TrainThanLastMonth); workbook.Replace(string.Format("${0}$", "ExamCount"), summaryLastMonth.ExamCount); workbook.Replace(string.Format("${0}$", "PassRate"), summaryLastMonth.PassRate); workbook.Replace(string.Format("${0}$", "CertCount"), summaryLastMonth.CertCount); workbook.Replace(string.Format("${0}$", "CertThanLastMonth"), summaryLastMonth.CertThanLastMonth); workbook.Replace(string.Format("${0}$", "ContinueEduCount"), summaryLastMonth.ContinueEduCount); workbook.Replace(string.Format("${0}$", "ChangeCertCount"), summaryLastMonth.ChangeCertCount);
           //省略N个处理......,处理方式与上面一样
    if (!System.IO.Directory.Exists(Server.MapPath("/UploadFileXLS"))) { System.IO.Directory.CreateDirectory(Server.MapPath("/UploadFileXLS")); } var filePath = "/UploadXLS/" + time.AddMonths(-1).Year + "" + time.AddMonths(-1).Month + "月份汇总表.xlsx"; var address = Server.MapPath(filePath); if (System.IO.File.Exists(address)) { System.IO.File.Delete(address); } workbook.Save(address);         return View(); }

     这样就处理好了

  • 相关阅读:
    NowCoder数列(矩阵快速幂变式)
    P1147 连续自然数和(思维题)
    P1029 最大公约数和最小公倍数问题(思维题)
    Diophantus of Alexandria
    欧拉筛法求素数( 洛谷)
    欧拉函数
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/xiaonangua/p/11696738.html
Copyright © 2020-2023  润新知