会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
代码改变世界
Cnblogs
Dashboard
Login
Home
Contact
Gallery
Subscribe
RSS
Rui
细节决定成败!
从GridView导出数据到Excel
2007-04-05 13:09
ruinet
阅读(
546
) 评论(
3
)
编辑
收藏
举报
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Export(
"
application/ms-excel
"
,
"
test.xls
"
);
}
private
void
Export(
string
FileType,
string
FileName)
{
Response.Charset
=
"
GB2312
"
;
Response.ContentEncoding
=
System.Text.Encoding.UTF7;
Response.AppendHeader(
"
Content-Disposition
"
,
"
attachment;filename=
"
+
HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType
=
FileType;
this
.EnableViewState
=
false
;
StringWriter tw
=
new
StringWriter();
HtmlTextWriter hw
=
new
HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public
override
void
VerifyRenderingInServerForm(Control control)
{
}
会员力量,点亮园子希望
刷新页面
返回顶部
About
free web counter