Response.ClearContent();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment; filename=EnergyReport" + DateTime.Now.ToString("_yyyyMMdd_HHmmss") + ".xls");
Response.ContentEncoding = System.Text.Encoding.Default;
Response.ContentType = "application/ms-excel";
gv.AllowPaging = false;
gv.DataBind();
this.EnableViewState = false;
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter tw = new System.IO.StringWriter(ci);
HtmlTextWriter hw = new HtmlTextWriter(tw);
gv.RenderControl(hw);
Response.Output.Write(tw.ToString());
gv.AllowPaging = true;
gv.DataBind();
Response.Flush();
Response.End();
红色是主要的!