asp.net gv导出excel

来源:互联网 发布:ipa应用分发源码 编辑:程序博客网 时间:2024/03/29 22:36

protected void btnExcel_Click(object sender, EventArgs e)
        {
            Response.Clear();

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

            Response.ContentType = "application/vnd.xls";

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite =
            new HtmlTextWriter(stringWrite);

            gvDB.RenderControl(htmlWrite);

            Response.Write(stringWrite.ToString());

            Response.End();
        }

原创粉丝点击