protected void Button1_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Charset = "gb2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
//Response.AddHeader("content=text/html,charset=GB2312");
Response.AddHeader("content-disposition", "attachment;filename=MyExcel.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
...
转载于:https://www.cnblogs.com/xiazhi33/articles/1119655.html