会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
chenrunuan
博客园
首页
新随笔
联系
订阅
管理
公告
C#导出Excel
Code
1
private
void
toExcel(DataTable tb)
2
{
3
System.Web.UI.WebControls.DataGrid dgrid
=
null
;
4
System.Web.HttpContext context
=
System.Web.HttpContext.Current;
5
System.IO.StringWriter strOur
=
null
;
6
System.Web.UI.HtmlTextWriter htmlWriter
=
null
;
7
if
((tb
!=
null
))
{
8
context.Response.ContentType
=
"
application/vnd.ms-excel
"
;
9
context.Response.ContentEncoding
=
System.Text.Encoding.UTF8;
10
context.Response.Charset
=
"
"
;
11
12
strOur
=
new
IO.StringWriter();
13
htmlWriter
=
new
System.Web.UI.HtmlTextWriter(strOur);
14
dgrid
=
new
DataGrid();
15
dgrid.DataSource
=
tb.DefaultView;
16
dgrid.AllowPaging
=
false
;
17
dgrid.DataBind();
18
19
dgrid.RenderControl(htmlWriter);
20
context.Response.Write(strOur.ToString);
21
context.Response.End();
22
}
23
}
posted on
2008-02-28 10:07
crn
阅读(
177
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3