将GridView的数据导出Excel

 1                 HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=CALLINTOTALLIST_Excel.xls");
 2                 HttpContext.Current.Response.Charset = "UTF-8";
 3                 HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
 4                 HttpContext.Current.Response.ContentType = "application/ms-excel";
 5                 Gri_CallInRecord.Page.EnableViewState = false;
 6                 System.IO.StringWriter tw = new System.IO.StringWriter();
 7                 System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
 8                 Gri_CallInRecord.RenderControl(hw);
 9                 HttpContext.Current.Response.Write(tw.ToString());
10                 HttpContext.Current.Response.End();                
View Code

开发语言:c#
开发环境:Win7+VS2008

开发模式:webForm

作用:用于导出GridView的数据,导出文件为Excel

posted on 2013-09-30 16:18  斗笠大侠  阅读(608)  评论(3编辑  收藏  举报

导航