会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
邀月工作室
年轻的时候,多走走,走不动的时候,静下来写回忆录。
3w@live.cn
博客园
首页
联系
订阅
管理
导出GridView到Excel中的关键之处(downmoon)
导出GridView到Excel中的关键之处(downmoon)
导出GridView到Excel中的关键之处
用法: ToExcel(GVStaff, TextBox1.Text);
public
static
void
ToExcel(System.Web.UI.Control ctl,
string
FileName)
...
{
HttpContext.Current.Response.Charset
=
"
UTF-8
"
;
HttpContext.Current.Response.ContentEncoding
=
System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType
=
"
application/ms-excel
"
;
HttpContext.Current.Response.AppendHeader(
"
Content-Disposition
"
,
"
attachment;filename=
"
+
""
+
FileName
+
"
.xls
"
);
ctl.Page.EnableViewState
=
false
;
System.IO.StringWriter tw
=
new
System.IO.StringWriter();
HtmlTextWriter hw
=
new
HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
必须有下面这句!否则不会通过!
public override void VerifyRenderingInServerForm(Control control)
...
{
// Confirms that an HtmlForm control is rendered for
}
邀月注:本文版权由邀月和博客园共同所有,转载请注明出处。
助人等于自助!
3w@live.cn
posted @
2007-12-29 08:56
邀月
阅读(
507
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告