没有合适的资源?快使用搜索试试~ 我知道了~
C#数据表中的数据导出到excel(web,WinFrom)
5星 · 超过95%的资源 需积分: 1 118 下载量 74 浏览量
2012-01-08
16:34:49
上传
评论
收藏 3KB TXT 举报
温馨提示
试读
4页
C#数据表中的数据导出到excel(web,WinFrom)
资源推荐
资源详情
资源评论
1.web
public void TableToExcel(System.Data.DataTable tb)
{
try
{
string Filename="person";
System.Web.HttpContext context = System.Web.HttpContext.Current;
if ((tb != null))
{
context.Response.Clear();
context.Response.Charset = "GB2312";
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
context.Response.ContentType = "application/ms-excel";
context.Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(Filename, System.Text.Encoding.GetEncoding("GB2312")) + ".xls\"");
System.Globalization.CultureInfo cult = new System.Globalization.CultureInfo("zh-CN", true);
StringWriter sw = new StringWriter(cult);
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid dgrid = new DataGrid();
dgrid.DataSource = tb.DefaultView;
dgrid.AllowPaging = false;
dgrid.DataBind();
htw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"textml;charset=GB2312\">");
dgrid.RenderControl(htw);
context.Response.Write(sw.ToString());
context.Response.End();
}
}
public void TableToExcel(System.Data.DataTable tb)
{
try
{
string Filename="person";
System.Web.HttpContext context = System.Web.HttpContext.Current;
if ((tb != null))
{
context.Response.Clear();
context.Response.Charset = "GB2312";
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
context.Response.ContentType = "application/ms-excel";
context.Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(Filename, System.Text.Encoding.GetEncoding("GB2312")) + ".xls\"");
System.Globalization.CultureInfo cult = new System.Globalization.CultureInfo("zh-CN", true);
StringWriter sw = new StringWriter(cult);
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid dgrid = new DataGrid();
dgrid.DataSource = tb.DefaultView;
dgrid.AllowPaging = false;
dgrid.DataBind();
htw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"textml;charset=GB2312\">");
dgrid.RenderControl(htw);
context.Response.Write(sw.ToString());
context.Response.End();
}
}
qs1208
- 粉丝: 9
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页