星空网 > 软件开发 > ASP.net

asp.net 导出Excel

分享一个asp.net 导出假Excel代码。优点,不用借助于任何插件比如(NPOI),复制代码,修改grid.DataSource直接导出。

先看导出后的效果图

asp.net 导出Excel

asp.net 导出Excelasp.net 导出Excel
 1 System.Web.UI.WebControls.DataGrid grid = new DataGrid(); 2         grid.CellSpacing = 6; 3         grid.CellPadding = 6; 4         grid.EnableViewState = false; 5         grid.DataSource = tableCars; 6         grid.DataBind(); 7         foreach (DataGridColumn clos in grid.Columns) 8         { 9           clos.HeaderStyle.Width = 200;10           clos.ItemStyle.Width = 200;11         }12         System.IO.StringWriter tw = new System.IO.StringWriter();13         HtmlTextWriter hw = new HtmlTextWriter(tw);14         grid.RenderControl(hw);15         string fileName = System.Web.HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls", System.Text.Encoding.UTF8);16         HttpContext.Current.Response.Charset = "utf-8";17         HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;18         HttpContext.Current.Response.ContentType = "application/ms-excel";19         HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);20         HttpContext.Current.Response.Write(tw.ToString());21         HttpContext.Current.Response.End();

View Code



原标题:asp.net 导出Excel

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

免费的外贸网站:https://www.goluckyvip.com/tag/38690.html
免费独立站:https://www.goluckyvip.com/tag/38692.html
免费关键词研究工具:https://www.goluckyvip.com/tag/38694.html
免费建站:https://www.goluckyvip.com/tag/38695.html
免费建站网站:https://www.goluckyvip.com/tag/38696.html
跨境薪酬制度:https://www.goluckyvip.com/tag/387.html
三百元以内千兆路由器怎么选择?:https://www.vstour.cn/a/363184.html
千岛湖绿城度假酒店的简介:https://www.vstour.cn/a/363185.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流