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

Reading number is top 10 articles
组合ASP.NET,2.0数据控件构建强大用户接口_.net资料_编程技术
ASP.NET,2.0,Language,Swithcer,and,Theme,Swicher,多语_[Asp.Net教程]
2.0里用DIV层元素弹出窗体_.net资料_编程技术
dropdownlist,datagrid数据绑定简单实现_[Asp.Net教程]
.NET,2.0,中对配置文件的读写_[Asp.Net教程]
ASP.NET中的File类和Directory类的相关知识_.net资料_编程技术
不使用VS进行ASP.NET,Membership管理_.net资料_编程技术
讲述PHP中Session的概念_php资料_编程技术
在sqlserver2005中安装sql server 2000的示例数据库_[SQL Server教程]
asp.net连接mysql_[Asp.Net教程]
Reading number is top 10 pictures
A man's favorite things10
Terrorist smile the largest human history an explosion1
清醇靓丽的美眉
Breasts woman big set 2
The household of rural style is designed
毛俊杰-能量永动机
怀春少女-石一伊
徐若瑄展示美丽胸围3
Forced sex girl living abroad2
Sora aoi in China2
Download software ranking
asp.net技术内幕
网络管理员第三版
WebService在.NET中的实战应用教学视频 → 第2集
The Bermuda triangle2
Boxer's Top ten classic battle9
matrix3
Sora aoi - one of more PK
仙剑奇侠传98硬盘WINXP版
Photoshop 8.0图象编辑软件
Tram sex maniac 2 (H) rar bag15
delv published in(发表于) 2014/1/6 9:04:05 Edit(编辑)
ASP.NET技巧:將datagrid控件內容輸出到excel文件_[Asp.Net教程]

ASP.NET技巧:將datagrid控件內容輸出到excel文件_[Asp.Net教程]

ASP.NET技巧:將datagrid控件內容輸出到excel文件_[Asp.Net教程]

一個將datagrid控件內容輸出到excel文件的demo.


生成EXCEL文件#region 生成EXCEL文件
public void setToExcel()
{
// Response.Clear();
// Response.Buffer= true;
// Response.Charset="utf-8";  

if (eformsn.Text=="")
{
DataGrid1.Visible=false;
Label1.Text="要匯入EXCEL,請先輸入申請單號!";
Label1.Visible=true;
}
else
{
dl.DataSource=DB("query", "select * from msi_eol_list_line where eformsn="+eformsn.Text+" order by eformsn").Tables[0].DefaultView;
dl.DataBind();


//下面這行很重要,attachment 參數表示作為附件下載,您可以改成online在線打開
//filename=FileFlow.xls 指定輸出文件的名稱,注意其擴展名和指定文件類型相符,可以為:.doc .xls .txt .htm  


Response.AppendHeader("Content-Disposition","attachment;filename=EOL_"+eformsn.Text+".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8"); 


//Response.ContentType指定文件類型 可以為application/ms-excel,application/ms-word ,application/ms-txt,application/ms-html或其他瀏覽器可直接支持文檔 
Response.ContentType = "application/ms-excel";
dl.EnableViewState = false; 


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


//將目標數據綁定到輸入流輸出  
//this 表示輸出本頁,你也可以綁定datagrid,或其他支持obj.RenderControl()屬性的控件  
dl.RenderControl(oHtmlTextWriter);
//this.DataBind.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
}
#endregion


来源:网络







添加到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.