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

repeater数据导出到Excel
如题.网上的代码也有,但效果不是很理想或不能实现.请大家帮下忙~~最好有实现的方法代码(asp.net(C#))

------解决方案--------------------

和 datagrid一样啊,基本原理也就是把数据库中的数据读出,组合成字符串输出就行了。。。
------解决方案--------------------
C# code


 protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=file.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);
        GridView1.AllowPaging = false;
        EnableViewState = false;

        GridView1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    }