当前位置:跳过导航链接计算机毕业设计首页 : 技术应用 : 详细内容

ASP.NET实现将Gridview中的内容转出到EXCEL

来源:本站原创 作者:管理员 添加时间:2011-02-20 点击数:1543

一、相关介绍:

在使用ASP.NET时,通常会使用到输出EXCEL功能,下面介绍如果使用ASP.NET实现GRIDVIEW的输出:

代码如下:

以下是引用片段:

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

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

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

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

        System.Web.UI.HtmlTextWriter htmlWrite =
        new HtmlTextWriter(stringWrite);
        GridView1.AllowPaging = false;
        bind();
        GridView1.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());

        Response.End();
        GridView1.AllowPaging = true;
        bind();
    }

<责任编辑:计算机毕业设计网(http://www.xiaoniu168.com)>

第1页

【联系方式】

【本站信誉】

用心做计算机毕业设计论文网