C # Generate form codes

Source: Internet
Author: User

Public ActionResult Btnexport (Reportviewmodel model) {//Receive data that needs to be exported List<reportviewmodel . employeeregister> list = Employeerepository.getemployeeprportall (model). ToList ();

The StringBuilder variable named export table StringBuilder sHtml = new StringBuilder (string. Empty);

           //Print header              shtml.append ("<table border=\" 1\ "width=\" 100%\ ">");                         //Print column name             shtml.append (" <tr height=\ "20\" align=\ "Center\" > "                         + "<td style=\" background-color:# 4474bb;font-weight:bold\ "> Serial number </td>"                          + "<td style=\" background-color:# 4474bb;font-weight:bold\ "> Work No. </td>"                          + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Name </td> "                         + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Gender </td> "                         + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Department </td> "                         + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Company subsidy </td> "                         + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Utility subsidy </td> "                         + "<td style=\" Background-color: #4474BB font-weight:bold\ "> Travel time </td>"                          + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Lines </td>"                          + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Travel Agency </td>"                          + "<td style=\" Background-color: #4474BB; font-weight:bold\ "> Sign-in Office </td>"                          + "</tr>");

           //Looping through the list collection              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> ");            }

           //Print the end of the table              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 ("Allowance usage report. 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= Allowance usage report. xls"); }

C # Generate form codes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.