//导出Excel 代码
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel"; //修改为word就导出word文件
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw); //GridView1为数据导出的控件
Response.Write(sw.ToString());
Response.End();
public override void VerifyRenderingInServerForm(Control control)
{
//此重载函数很重要,否则导出EXCEL时会报错
}