導出Excel

人走茶凉 提交于 2020-01-21 14:16:15

 GridView2.Columns[4].Visible=false;

        GridView2.Columns[5].Visible = false;

        Response.Clear();

        Response.Charset = "GB2312";

        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");

        //如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!

        Response.ContentEncoding = System.Text.Encoding.UTF7;

        Response.ContentType = "application/ms-excel"; //设置输出文件类型为excel文件。

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

        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

        GridView2.AllowPaging = false;

        this.GridView2.RenderControl(oHtmlTextWriter);

        Response.Output.Write(oStringWriter.ToString());

        Response.Flush();

        Response.End();

        GridView2.Columns[4].Visible=true ;

        GridView2.Columns[5].Visible = true;

        BingData();   

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!