没有合适的资源?快使用搜索试试~ 我知道了~
C#数据表中的数据导出到excel(web,WinFrom)
5星 · 超过95%的资源 需积分: 1 118 下载量 141 浏览量
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币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- #P0015. 全排列 超级简单
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页