马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

Repeater导出Excel格式

[复制链接]
查看4363 | 回复2 | 2014-7-7 09:05:49 | 显示全部楼层 |阅读模式
将Repeater的数据,导出为Excel,一般都是datagridview导出excel,今天直接上Repeater导出excel
就一个方法:

[C#] 纯文本查看 复制代码
 /// <summary>
        /// Repeater统计导出,Excel格式
        /// </summary>
        /// <param name="ctl"></param>
        public static void ToExcel(System.Web.UI.Control ctl)
        {
            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();
        }



参数为Repeater控件的ID
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
sherlockhomles | 2014-7-7 09:08:57 | 显示全部楼层
等待时候 | 2014-7-7 14:22:09 | 显示全部楼层
過來赞一个
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则