简单代码:
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=ExportFile.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();