• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#HTML转EXCEL的方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 1         private void ToExcel(string html)
 2         {
 3 
 4             Response.ContentType = "application/force-download";
 5             Response.AddHeader("content-disposition",
 6                 "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
 7             Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
 8             Response.Write("<head>");
 9             Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
10             string fileCss = Server.MapPath("~/UI/themes/DRP.UI.Ext.css");
11             string cssText = string.Empty;
12             StreamReader sr = new StreamReader(fileCss);
13             var line = string.Empty;
14             while ((line = sr.ReadLine()) != null)
15             {
16                 cssText += line;
17             }
18             sr.Close();
19             Response.Write("<style>" + cssText + "</style>");
20             Response.Write("<!--[if gte mso 9]><xml>");
21             Response.Write("<x:ExcelWorkbook>");
22             Response.Write("<x:ExcelWorksheets>");
23             Response.Write("<x:ExcelWorksheet>");
24             Response.Write("<x:Name>Report Data</x:Name>");
25             Response.Write("<x:WorksheetOptions>");
26             Response.Write("<x:Print>");
27             Response.Write("<x:ValidPrinterInfo/>");
28             Response.Write("</x:Print>");
29             Response.Write("</x:WorksheetOptions>");
30             Response.Write("</x:ExcelWorksheet>");
31             Response.Write("</x:ExcelWorksheets>");
32             Response.Write("</x:ExcelWorkbook>");
33             Response.Write("</xml>");
34             Response.Write("<![endif]--> ");
35             Response.Write(html);//HTML
36             Response.Flush();
37             Response.End();
38         }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
今天被《C#入门经典》给忽悠了发布时间:2022-07-10
下一篇:
C#managed,unmanaged,unsafe的比较发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap