如何将gridview的数据导出到EXCEL?
的有关信息介绍如下:给你个思路,分页的话,在导出时先关闭分页,绑数据,导出后,再打开分页方法1简单: public void ToExcel()//整个GRIDVIEW导出到EXCEL { string filename="数据表" + DateTime.Now.ToString("yyyyMMdd") + ".xls"; string style = @" .text { mso-number-format:\@; } "; //解决第一位字符为零时不显示的问题 this.GridView1.AllowPaging = false;//关闭分页 this.GridView1.DataBind();//绑定数据 filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);//解决导出EXCEL时文件名为汉字时乱码的问题 Response.ClearContent; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.ContentType = "application/excel"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename); System.IO.StringWriter sw = new System.IO.StringWriter();//定义一个字符串写入对象 HtmlTextWriter htw = new HtmlTextWriter(sw);//将html写到服务器控件输出流 this.GridView1.RenderControl(htw);//将控件GRIDVIEW中的内容输出到HTW中 Response.Write(style); Response.Write(sw); Response.End(); this.GridView1.AllowPaging = true; }本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fangqm/archive/2009/08/01/4400306.aspx