亲宝软件园·资讯

展开

asp.net GridView导出Excel asp.net GridView导出到Excel代码

人气:0
想了解asp.net GridView导出到Excel代码的相关内容吗,在本文为您仔细讲解asp.net GridView导出Excel的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:asp.net,GridView,Excel,下面大家一起来学习吧。
复制代码 代码如下:

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
GVLinkman.EnableViewState = false;
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GVLinkman);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=data.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();

加载全部内容

相关教程
猜你喜欢
用户评论