zoukankan      html  css  js  c++  java
  • ASP.NET导出excel代码

    public ActionResult Export()
            {
                string table = "<table border='1px solid black'><tr><td>编号</td><td>真实姓名</td><td>昵称</td><td>电话</td><td>数量</td><td>参与时间</td><td>状态</td><td>备注</td></tr>";
                table += "<tr><td>1</td><td>2</td><td>3</td><td>4<td>5</td><td>6</td><td>6</td><td>6</td></tr>";
                table += "</table>";
               string fileName = "游戏活动模板" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                Response.ContentType = "application/force-download";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                Response.Write("<html xmlns:x="urn:schemas-microsoft-com:office:excel">");
                Response.Write("<head>");
                Response.Write("<META http-equiv="Content-Type" content="text/html; charset=utf-8">");
                //Response.ContentType = "application/excel";
                //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                Response.Write("<!--[if gte mso 9]><xml>");
                Response.Write("<x:ExcelWorkbook>");
                Response.Write("<x:ExcelWorksheets>");
                Response.Write("<x:ExcelWorksheet>");
                Response.Write("<x:Name>Report Data</x:Name>");
                Response.Write("<x:WorksheetOptions>");
                Response.Write("<x:Print>");
                Response.Write("<x:ValidPrinterInfo/>");
                Response.Write("</x:Print>");
                Response.Write("</x:WorksheetOptions>");
                Response.Write("</x:ExcelWorksheet>");
                Response.Write("</x:ExcelWorksheets>");
                Response.Write("</x:ExcelWorkbook>");
                Response.Write("</xml>");
                Response.Write("<![endif]--> ");
                Response.Write(table);
                Response.End();
            }
  • 相关阅读:
    flask_日期和时间
    使用SQLAlchemy对博客文章进行分页
    P2725 邮票 Stamps
    P2679 子串
    P3396 哈希冲突
    P1754 球迷购票问题
    P1504 积木城堡
    P1244 青蛙过河
    CSP-S 2019 考试分析
    2019.11.11 模拟赛 T2 乘积求和
  • 原文地址:https://www.cnblogs.com/wenghan/p/12514457.html
Copyright © 2011-2022 走看看