All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#简介-,类和对象_[Asp.Net教程]
如何使用delphi调用外部EXE文件
.net仿照51job网站地区选择效果_[Asp.Net教程]
让Windows主机在IIS支持PHP和MySQL_[PHP教程]
ASP.NET,2.0发送电子邮件中存在的问题_.net资料_编程技术
asp.net2.0中关于ASP.NET,网站管理工具无法连接sql,server,数据库的处理_[Asp.Net教程]
实现在新闻标题后加new图片_[Asp.Net教程]
PHP技巧:PHP文件系统基本操作类_[PHP教程]
此方法用于确认用户输入的不是恶意信息_.net资料_编程技术
SQL数据库高级教程:SQL ALTER TABLE_[SQL Server教程]
Reading number is top 10 pictures
No trading, no killing
Sora aoi in China3
色狗系列
Born After 90 Beijing sports university campus flower photos5
美女浴室写真2
Chinese paper-cut grilles art appreciation6
Men don't mature ten sign
Fierce chengdu woman, street rape man
Ashlynn Brooke a group sexy photo4
美女浴室写真3
Download software ranking
Unix video tutorial13
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
少妇苏霞全本
The Bermuda triangle3
Tram sex maniac 2 (H) rar bag1
软件工程思想
Tram sex maniac 2 (H) rar bag12
Tram sex maniac 2 (H) rar bag19
双旗镇刀客B
天龙八部十二宫服务端
归海一刀 published in(发表于) 2014/1/30 1:10:20 Edit(编辑)
将DataGrid或GridView中的数据生成Excel_[Asp.Net教程]

将DataGrid或GridView中的数据生成Excel_[Asp.Net教程]

将DataGrid或GridView中的数据生成Excel_[Asp.Net教程]

下面是一个将DataGrid中的数据生成Excel文档的方法,其中System.Web.UI.Control ctl指DataGrid的ID,


FileName指要生成Excel文件的名称。


//生成Excel文件
public void ToExcel(System.Web.UI.Control ctl, string FileName)
{
//设置网络输出流的HTTP字符集为UTF-8,Current为当前 HTTP 请求获取 HttpContext 对象
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
//设置输出流HTTPMIME类型为excel
HttpContext.Current.Response.ContentType = "application/ms-excel";
//将HTTP头添加到输出流
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+ FileName+".xls");
//不保存该控件的视图状态
ctl.Page.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
//将文本写入到输出流
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
//将服务器控件的内容输出到HtmlTextWriter对象中
ctl.RenderControl(hw);
//StringWriter.ToString返回包含迄今为止写入到当前 StringWriter 中的字符的字符串
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();

}







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.