日期:2014-05-18  浏览次数:20482 次

Repeater导出excel
Repeater导出excel,我导出的都是html代码,望大家帮忙谢谢!

C# code

 private void repeaterToExecl(Repeater r)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "inline;filename=test.xls");

            Response.Charset = "GB2312";
            Response.ContentEncoding = Encoding.UTF8;

            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

            Page.EnableViewState = false;

            r.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End(); 


        }



------解决方案--------------------
rpt.DataSourse=??;
rpt.DataBind();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
string FileName = "111.xls";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
rpt.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
------解决方案--------------------
要不将数据源导出到Excel,要不用excel组件自定义导出……
------解决方案--------------------
顶1楼
------解决方案--------------------
up
------解决方案--------------------
顶一楼
------解决方案--------------------
up