AspNet GridView Excel 下载 Excel 导出
1.GridView
- AutoGenerateColums =false;
- DataSource
- DataBind
2.BoundField
- DataField
- HeaderText
- ItemStyle.HorizontalAlign
- Visible
3.StringWriter sw =new StringWriter ();
4.HtmlTextWriter htw =new HtmlTextWriter(sw);
5.Gridview.RenderConterol(htw)
6.Response
- Response.ClearContent();
- Response.AddHeader("content-disposition", "attachment; filename=name.xls");
- Response.ContentType = "application/unknown";
- Response.Write("<meta http-equiv='Content-Type' content='text/html; charset=" + Request.ContentEncoding.HeaderName+ "'>");
- Response.Write(sw.ToString());
- Response.End();