当前位置:编程学习 > C#/ASP.NET >>

Repeater 导出execl

怎 么弄啊,
现在导的把LI,UL都弄出来了,
怎 么把这些去掉啊






















--------------------编程问答-------------------- 呵呵,自己写导出语句生成 "<table><tr><td>000</td></tr></table>"这样的string然后输出到客户端 --------------------编程问答-------------------- 通过JS在客户端直接读取,然后通过IE的SAVEAS实现导出

var obj="";
obj=按要求读取的内容
......

var newwin     =window.open(" ","_blank","width=1,height=1,scrollbars=no,toolbar=no");
newwin.document.write(obj);
newwin.document.execCommand("saveas",false,ExcelFileName)) ;
newwin.opener=null;
newwin.close(); --------------------编程问答-------------------- 可以先将reapter 转换成html 软后再生成excel


   //将html导出成excel
   public void OutHtmlToExcel(string html)
        {
            string FileName = "oec2003.xls";
            System.Web.HttpResponse httpResponse = this.Page.Response;

            httpResponse.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
            httpResponse.ContentEncoding =System.Text.Encoding.Default;
            httpResponse.ContentType = "application/ms-excel";
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

            string filePath = Page.Server.MapPath(".") + "\\" + FileName;

            System.IO.StreamWriter sw = System.IO.File.CreateText(filePath);
            sw.Write(html);
            sw.Close();

            httpResponse.Write(html);
            httpResponse.End();
        }

  protected void Button3_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder strb = new System.Text.StringBuilder();
            System.IO.StringWriter sw = new System.IO.StringWriter(strb);
            System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);
            //执行控件的render并输出到HtmlTextWriter里
              this.Repeater1.RenderControl(htw);
            string s = strb.ToString();

            OutHtmlToExcel(s);

        }

补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,