zoukankan      html  css  js  c++  java
  • C#将HTML导出Excel

    string html = "<table><tr><td>1</td><td>11</td></tr><tr><td>2</td><td>22</td></tr></table>";
                    Response.ContentType = "application/force-download";
                    Response.AddHeader("content-disposition",
                        "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
                    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">");
                    string fileCss = Server.MapPath("~/css/daoChuCSS.css");
                    string cssText = string.Empty;
                    StreamReader sr = new StreamReader(fileCss);
                    var line = string.Empty;
                    while ((line = sr.ReadLine()) != null)
                    {
                        cssText += line;
                    }
                    sr.Close();
                    Response.Write("<style>" + cssText + "</style>");
                    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(html);//HTML
                    Response.Flush();
                    Response.End();
  • 相关阅读:
    课件的引子
    用nc做网络压力测试
    分布式计算学习笔记
    静态库 .a 转成共享库 .so
    nmon用法
    eclipse debug URLClassPath.getLoader(int) file
    sodu 命令场景分析
    俩孩随笔
    深度学习丨深度学习中GPU和显存分析
    语义分割丨DeepLab系列总结「v1、v2、v3、v3+」
  • 原文地址:https://www.cnblogs.com/axu92312/p/5956110.html
Copyright © 2011-2022 走看看