zoukankan      html  css  js  c++  java
  • 数据写入到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(); }

     这样就处理好了

  • 相关阅读:
    从零开始学CSS-overflow
    vue 高度自适应的问题处理
    子div在父div里居中
    IEC104协议规约解析
    Arduino编译总结
    通过golang小案例,了解golang程序常见机制
    用go实现常见的数据结构
    常见面试题整理,金三银四全靠它了
    golang知识总结
    .NET Core 基于 Grafana Loki 日志初体验
  • 原文地址:https://www.cnblogs.com/xiaonangua/p/11696738.html
Copyright © 2011-2022 走看看