C# HTML转EXCEL的方法
出处:互联网  更新时间:2022-04-23
private void ToExcel(string html)
        {

            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("~/UI/themes/DRP.UI.Ext.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();
        }
网站申明:系本文编辑转载,来源于网络,目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,所有权归属原作者。如内容、图片有任何版权问题,可联系我们删除
正在被浏览的文章
IT编程技术  互联网  2022-04-23
新闻动态  财经头条  2018-07-14
新闻动态  互联网  2018-09-01
热点文章
物流问答  互联网  2017-01-08
物流问答  互联网  2017-01-08
更多精彩文章点此进入
长按下图选择“设别图中二维码”关注公众号
微信公众号