zoukankan      html  css  js  c++  java
  • C# 生成表格代碼

     public ActionResult btnExport(ReportViewModel model)         {             //接收需要导出的数据             List<ReportViewModel.EmployeeRegister> list = EmployeeRepository.GetEmployeePrportAll(model).ToList();

                //命名导出表格的StringBuilder变量             StringBuilder sHtml = new StringBuilder(string.Empty);

                //打印表头             sHtml.Append("<table border="1" width="100%">");                         //打印列名             sHtml.Append("<tr height="20" align="center" >"                         + "<td style="background-color:#4474BB;font-weight:bold">序号</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">工号</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">姓名</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">性别</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">部门</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">公司补助</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">实用补助</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">出游时间</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">线路</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">旅行社</td>"                         + "<td style="background-color:#4474BB;font-weight:bold">签到处</td>"                         + "</tr>");

                //循环读取List集合             for (int i = 0; i < list.Count; i++)             {                 sHtml.Append("<tr height="20" align="left">"                         + "<td>" + list[i].ListIndex + "</td>"                         + "<td>" + list[i].EmployeeNo + "</td>"                         + "<td>" + list[i].EmployeeNm + "</td>"                         + "<td>" + list[i].SexCN + "</td>"                         + "<td>" + list[i].Dept + "</td>"                         + "<td style="color:Red">" + list[i].Subsidy + "</td>"                         + "<td style="color:Red">" + list[i].UseSubsidy + "</td>"                         + "<td>" + list[i].GroupDt + "</td>"                         + "<td>" + list[i].ProductNm + "</td>"                         + "<td>" + list[i].AgenciesNm + "</td>"                         + "<td></td>"                         + "</tr>");             }

                //打印表尾             sHtml.Append("</table>");

                System.Web.HttpContext.Current.Response.Charset = "UTF-8";             System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;             System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("津贴使用報表.xls", System.Text.Encoding.UTF8).ToString());             System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";             System.IO.StringWriter tw = new System.IO.StringWriter();             System.Web.HttpContext.Current.Response.Output.Write(sHtml.ToString());             System.Web.HttpContext.Current.Response.Flush();             System.Web.HttpContext.Current.Response.End();

       return File(sHtml.ToString(), "attachment;filename=津贴使用報表.xls");         }

  • 相关阅读:
    为什么Java的main方法必须是public static void?
    2. 直接插入、折半插入、希尔排序及其比较(插入类排序)
    1. 冒泡与选择排序及其比较
    0.排序介绍与性能度量
    (十)更快的排序算法(归并、快排、基数)
    (九)排序(选择、插入、希尔)
    (八)递归
    (七)栈的三种实现
    (六)栈的规则及应用
    (五)如何写测试类
  • 原文地址:https://www.cnblogs.com/qhy1277/p/4686513.html
Copyright © 2011-2022 走看看