码迷,mamicode.com
首页 > Web开发 > 详细

将ASP.NET 数据导出到execl

时间:2015-01-22 14:47:13      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

技术分享 将上图数据保存到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(); 
 

        }  技术分享 

 
 

将ASP.NET 数据导出到execl

标签:

原文地址:http://www.cnblogs.com/jiangyongyawen/p/4241343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!