码迷,mamicode.com
首页 > Windows程序 > 详细

C#将HTML导出Excel

时间:2016-10-13 15:00:45      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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();

C#将HTML导出Excel

标签:

原文地址:http://www.cnblogs.com/axu92312/p/5956110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!