将ASP.NET 数据导出到execl

图片 将上图数据保存到execl

//导出到execl
        protected void Execl_Click(object sender, EventArgs e)
        {
            System.Web.UI.Control ctl = this.Repeater1;
            //Repeater1是你在窗体中拖放的控件
 
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
            HttpContext.Current.Response.Charset = "UTF-8";
 
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
 
            ctl.Page.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End(); 
 

        }  图片 

 
 
posted @ 2015-01-22 12:31  Bodyjiang  阅读(133)  评论(0编辑  收藏  举报