html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

DataGrid导成Excel 的例子_.NET教程_编程技术

[ ] 已经帮助:人解决问题
datagrid|excel
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid dg = new DataGrid();
dg.DataSource = GetDataSource(); //返回DataSet或DataTable
dg.DataBind();
dg.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

如果导出有乱码:Response.ContentEncoding = System.Text.Encoding.UTF8


7JqHTML5中文学习网 - HTML5先行者学习网
7JqHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助