C#: Excel导出
来源:互联网 发布:java读取xlsx文件 编辑:程序博客网 时间:2024/06/05 16:36
Excel导出
===========================================================
//绑定需要输出的表
DataTable dt = (DataTable)this.Session["TempTest"] ;
this.dg_save.DataSource = dt ;
this.dg_save.DataBind() ;
//---------------------------------------------------------
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8 ;
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
// HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType ="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
//关闭控件的视图状态
this.dg_save.Page.EnableViewState =false;
//初始化writer
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
this.dg_save.RenderControl(hw);
//输出
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
DataTable dt = (DataTable)this.Session["TempTest"] ;
this.dg_save.DataSource = dt ;
this.dg_save.DataBind() ;
//---------------------------------------------------------
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8 ;
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
// HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType ="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
//关闭控件的视图状态
this.dg_save.Page.EnableViewState =false;
//初始化writer
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
this.dg_save.RenderControl(hw);
//输出
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
- DataGrid导出Excel(c#)
- 导出EXCEL代码(C#)
- C#: Excel导出
- 导出EXCEL代码(C#)
- 导出EXCEL代码(C#)
- C#Excel数据导出
- C#Excel导入导出
- C#winForm导出excel
- C#Excel导入导出
- c#excel导出
- C#Winform导出Excel
- C#:excel导入导出
- C#Winform导出Excel
- C#excel导入导出
- 【C#】数据导出到Excel
- C#.NET导出EXCEL表格
- C#Excel导入和导出
- C#Excel导入和导出
- 用C#获取系统内存
- 转帖]对计算机科学的反思
- 计算机科学漫谈--转载
- .NET Framework 1.1中请求被拒绝的解决办法
- 用.NET 2.0压缩/解压功能处理大型数据
- C#: Excel导出
- c#: 打包并自动安装SQL数据库
- c# : 无刷新取得远程数据
- 姚期智:锻造计算机科学拔尖人才--转载
- c#: 向后台发送消息
- 自定义应用程序主题或皮肤(by vb.net 2005)
- [ASP.NET] Session 详解
- speed
- ps视频教程