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

将GridView数据导入到excel,并提供下载

之前项目中需要一个导出数据到Excel的功能,现在将代码记录下来。其实将girdView中的数据导出的代码很简单,如下:

将GridView数据导入到excel,并提供下载将GridView数据导入到excel,并提供下载
 1 if (GvList.Rows.Count > 0) 2       { 3         Response.Charset="GB2312"; 4         Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 5         Response.AppendHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls"); 6         Response.ContentType = "application/vnd.ms-excel"; 7         StringWriter sw = new StringWriter(); 8         HtmlTextWriter htw = new HtmlTextWriter(sw); 9         GvList.RenderControl(htw);10         Response.Write(sw.ToString());11         Response.Flush();12         Response.End();13       }14       else15       {16         Response.Write("<script>alert('无日志数据!');</script>");17       }

后台代码
以上导出的数据为girdView的一页的数据,如果想将所有的数据导出,就得取消girdView的分页,AllowPaging设置为false,并重新绑定girdView,导出后在恢复原样。



原标题:将GridView数据导入到excel,并提供下载

关键词:GridView

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

马来西亚物流收费标准:https://www.goluckyvip.com/tag/91210.html
中国发马来西亚物流价格:https://www.goluckyvip.com/tag/91211.html
国内邮寄到马来西亚多少钱:https://www.goluckyvip.com/tag/91212.html
国内寄快运到马来西亚多少钱:https://www.goluckyvip.com/tag/91213.html
快运到马来西亚价格:https://www.goluckyvip.com/tag/91214.html
广州到马来西亚物流价格:https://www.goluckyvip.com/tag/91215.html
2024.04.18亚马逊选品推荐(仅供参考):女装蛋糕连衣裙:https://www.kjdsnews.com/a/1842234.html
欧洲市场疯了,订单排到7、8月!:https://www.kjdsnews.com/a/1842235.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流