Web gridview 导出Excel
Response.Clear();
Response.Buffer=true;
Response.Charset="GB2312";//
Response.AddHeader("Content-Disposition","attachment;filename=filename.xls");
Response.ContentEncoding=Encoding.UTF8;
Response.ContentType="Application/ms-excel";
System.IO.StringWriter writer=new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlwriter=new System.Web.UI.HtmlTextWriter(writer);
GridView1.RenderToControl(htmlwriter);
Response.output.write(writer.ToString());
Response.Flush();
Response.End();
1.还要页面上加一个 EnableEventValidation="false"
2.重载一个方法
public override void VerifyRenderingInServerForm(Control control)
{
}
Response.Buffer=true;
Response.Charset="GB2312";//
Response.AddHeader("Content-Disposition","attachment;filename=filename.xls");
Response.ContentEncoding=Encoding.UTF8;
Response.ContentType="Application/ms-excel";
System.IO.StringWriter writer=new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlwriter=new System.Web.UI.HtmlTextWriter(writer);
GridView1.RenderToControl(htmlwriter);
Response.output.write(writer.ToString());
Response.Flush();
Response.End();
1.还要页面上加一个 EnableEventValidation="false"
2.重载一个方法
public override void VerifyRenderingInServerForm(Control control)
{
}