asp.net将内容导出到Excel,Table表格数据(html)导出EXCEL
生活随笔
收集整理的這篇文章主要介紹了
asp.net将内容导出到Excel,Table表格数据(html)导出EXCEL
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼:
1 /// <summary> 2 /// HTML Table表格數據(html)導出EXCEL 3 /// </summary> 4 /// <param name="tableHeader">表頭</param> 5 /// <param name="tableContent">內容</param> 6 /// <param name="sheetName">文件名稱</param> 7 public void ExportToExcel(string tableHeader,string tableContent,string sheetName) 8 { 9 string fileName = sheetName + DateTime.Now.ToString("yyyyMMddHHmmss"); 10 string tabData = htmlTable; 11 if (tabData != null) 12 { 13 StringWriter sw = new System.IO.StringWriter(); 14 sw.WriteLine("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body>"); 15 sw.WriteLine("<table>"); 16 sw.WriteLine("<tr style=\"background-color: #e4ecf7; text-align: center; font-weight: bold\">"); 17 sw.WriteLine(tableHeader); 18 sw.WriteLine("</tr>"); 19 sw.WriteLine(tableContent); 20 sw.WriteLine("</table>"); 21 sw.WriteLine("</body>"); 22 sw.WriteLine("</html>"); 23 sw.Close(); 24 Response.Clear(); 25 Response.Buffer = true; 26 Response.Charset = "UTF-8"; 27 //Response.Charset = "GB2312"; 28 //this.EnableViewState = false; 29 Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls"); 30 Response.ContentType = "application/ms-excel"; 31 Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); 32 Response.Write(sw); 33 Response.End(); 34 } 35 }
?
轉載于:https://www.cnblogs.com/linJie1930906722/p/5215925.html
總結
以上是生活随笔為你收集整理的asp.net将内容导出到Excel,Table表格数据(html)导出EXCEL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一些必读的开源项目
- 下一篇: 【甘道夫】CDH5.2的Maven依赖