protected void Button4_Click(object sender, EventArgs e)
{
GridView1.Focus();
Response.Clear();
Response.Charset = "GB2312";
Response.Buffer = false;
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());Response.End();
}
- 本文标题: GridView 导出Excel ASP.NET
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.