StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
GridView1.EnableViewState = false;
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=data.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();
![](https://i-blog.csdnimg.cn/blog_migrate/dddfea6cd5b9bce7df9e9686b8121d34.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/41727c2185b74240dfdf3e9dce4e489e.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/992938e3a7fc2e01889fb04be152d3aa.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9e8ca7e9e004d03c8af14c2daef3757b.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0ac14485fe15a38e4b2dea7bcf9f53fd.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/c6bf77af81bcfe265441dcf8476aabfb.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/da829cc7db7a9938516842fd9c0b4db3.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0946722d78405cf630c1b4d25b89c6fa.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/fdbfc15931cddebd2724913c30923c9c.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/df709b2d1be48c50e9d78eabfaa67ddb.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b7a62b99afea79d10230bd5e4a57056b.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0fb3a2decdac37a3a87ddd159a40ceec.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a1d730d4763aef72feae0119bcf3e741.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/cf6194e4cd63d215850cffaafb891fe6.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/f938fc5d5fe6f792a1e5ecdb595863c2.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a9f0ebc800ef03e83a6169b35809d865.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/80bf4245555c477be0dbb8642f735aed.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/248aef79c5e464141b4d7ad583cb9bbf.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6e4bcc365ee8e647d3ad281e099b84ed.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/8a28b018f8e16e9170db249b154b8887.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/3897d75ecf1d9004325aa48db73d5b9b.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1f1dc84ea0243492fbb269a7502a586b.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b4afefcb9a66cf42b48caa7b04489ee2.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/c34da7e0f80759abcfcb7d89817e8288.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/38746f9ad005fb610ccbcd1fe1f0511a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1de90663f3ebcd089ba4016081bb2663.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/746716198848bec75d52cd964cbffeca.gif)