gridview导出excel,excel 第一行表头如何加排序?? Response.Clear(); Response.Buffer = true; Response.Charset = "UTF-8"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("SeasonalReport")) + "_" + TextBox1.Text + "_" + TextBox3.Text + " factory" + "_" + TextBox2.Text + "round" + ".xls");
GridView1.AllowPaging = false;
GridView1.AllowSorting = false; GridView1.DataBind(); Response.ContentEncoding = System.Text.Encoding.Default; Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw);
GridView1.RenderControl(tw);
Response.Output.Write(sw.ToString());
Response.Flush(); Response.End(); GridView1.AllowPaging = true; GridView1.DataBind();
GridView1.AllowPaging = false;
GridView1.AllowSorting = false; GridView1.DataBind(); Response.ContentEncoding = System.Text.Encoding.Default; Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw);
GridView1.RenderControl(tw);
Response.Output.Write(sw.ToString());
Response.Flush(); Response.End(); GridView1.AllowPaging = true; GridView1.DataBind();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货