gridview导出excel总结
HttpContext curContext = System.Web.HttpContext.Current;
System.IO.StringWriter strWriter = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);
curContext.Response.ContentType = "application/vnd.ms-excel";
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
curContext.Response.ContentEncoding = Encoding.GetEncoding("GB2312");
curContext.Response.Charset = "GB2312";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=zhddclxt;uid=sa;pwd=sa";
conn.Open();
SqlCommand cmd = new SqlCommand("select * from allorder", conn);
cmd.ExecuteNonQuery();
SqlDataReader DT = cmd.ExecuteReader();
GridView GV = new GridView();//一个无分页的GridView
GV.DataSource = DT;
GV.AllowPaging = false;
GV.DataBind();
GV.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString());
curContext.Response.End();