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(); }

     这样就处理好了

  • 相关阅读:
    Linux Shell系列教程之(十七) Shell文件包含
    Linux Shell系列教程之(十六) Shell输入输出重定向
    Linux Shell系列教程之(十五) Shell函数简介
    Linux Shell系列教程之(十四) Shell Select教程
    Linux Shell系列教程之(十三)Shell分支语句case … esac教程
    Linux Shell系列教程之(十二)Shell until循环
    Linux Shell系列教程
    算法系列:链表
    C++ 系列:Boost Thread 编程指南
    C++:多线程002
  • 原文地址:https://www.cnblogs.com/xiaonangua/p/11696738.html
Copyright © 2011-2022 走看看