有没有能把repeater中的数据直接生成excel的方法,不用再对数据库进行查询操作,就把当前页面已呈现的数据用excel导出来

解决方案 »

  1.   

    excel组件 一格格的写
      

  2.   

    //必须放在具有 runat=server 的窗体标记内
            //导出到Excel用
            public override void VerifyRenderingInServerForm(Control control)
            {
            }
    /// <summary>
            /// 导出数据到Excel
            /// </summary>
            public static void Export(Page pg, Repeater rep, string FileName)
            {
                pg.Response.Clear();
                pg.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                pg.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
                pg.Response.ContentEncoding = System.Text.Encoding.UTF8;
                pg.Response.ContentType = "application/vnd.ms-excel";//设置输出文件类型为excel文件。 
                pg.Response.Charset = "";
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                rep.RenderControl(oHtmlTextWriter);
                pg.Response.Output.Write(oStringWriter.ToString());
                pg.Response.End();
            }
      

  3.   

    System.IO.StringWriter sw = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
                this.Repeater1.RenderControl(hw);            Response.Clear();
                Response.ContentType = "application/vnd.ms-excel";
                Response.Charset = "";
                Page.EnableViewState = false;
                Response.AppendHeader("Content-Disposition", "attachment;filename=A.xls");
                Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"><title></title></head><body><center>");
                Response.Write(sw.ToString());
                Response.Write("</center></body></html>");
                Response.End();
      

  4.   

    好象很多的report都带导出EXCEL功能。没必要自己。随便找一个用是的。
      

  5.   

    你这个导出来之前 你绑定数据的时候用的肯定是dataset 或datatable 可以网上找下这两个导出excel的代码 多的是
      

  6.   

    System.IO.StringWriter sw = new System.IO.StringWriter();
      System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
      this.Repeater1.RenderControl(hw);  Response.Clear();
      Response.ContentType = "application/vnd.ms-excel";
      Response.Charset = "";
      Page.EnableViewState = false;
      Response.AppendHeader("Content-Disposition", "attachment;filename=A.xls");
      Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"><title></title></head><body><center>");
      Response.Write(sw.ToString());
      Response.Write("</center></body></html>");
      Response.End();
      

  7.   

    可以不需要再对数据库进行查询操作的啊,你直接取repeater的DataSource