• 数据写入到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(); }

     这样就处理好了

  • 相关阅读:
    Moodle 3.8 安装过程
    Discourse 数据分发
    Moodle 安装的时候提示 original IP
    Apache 安装运行测时候提示错误 (13)Permission denied: AH00091: httpd: could not open error log file
    Apache 配置 SELinux 命令的时候的命令 semanage
    Apache Httpd 安装 AH00558错误
    Discourse 如何修改用户自己的密码
    Discourse 如何限制注册用户的密码长度
    Discourse 的快捷键列表
    S3 存储附件和图片无法上传
  • 原文地址:https://www.cnblogs.com/xiaonangua/p/11696738.html
Copyright © 2020-2023  润新知