GridView导入excel中代码很简单的如
protected void ExportExcel(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "gb2312";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
this.GridData.AllowPaging = false;
BindData();//数据绑定
this.GridData.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
this.GridData.AllowPaging = true;
BindData();//数据绑定
}