http://m.cnblogs.com/39269/1606266.html

这是把显示在gridview里的数据导出到exl里面。

点击button1按钮。

protected void Button1_Click(object sender, EventArgs e)
    {

        Response.AddHeader("content-disposition", "attachment; filename=SysSta.xls");

        Response.ContentType = "application/excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

    //这里的gv。指的是gridview的ID.
       gv.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();
 
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        // Confirms that an HtmlForm control is rendered for
    }

 

posted on 2010-04-18 15:18  挑战自我  阅读(170)  评论(0编辑  收藏  举报