PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > ASP.NET教程 > 正文

    如何把gridview的数据全部导出excel

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读: <summary> 导出全部数据 < summary> <param name="FileType">< param> <param nam...
    // <summary>
            /// 导出全部数据
            /// </summary>
            /// <param name="FileType"></param>
            /// <param name="FileName"></param>
            protected void Button6_Click(object sender, EventArgs e)
            {
     
                GridView1.AllowPaging = false; //清除分页
                GridView1.AllowSorting = false; //清除排序   
                GetDataALL (); //你绑定gridview1数据源的那个函数。
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "GB2312";
                Response.AppendHeader("Content-Disposition", "attachment;filename=AllData.xls"); //.xls的文件名可修改
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                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);
                GridView1.RenderControl(oHtmlTextWriter);
                Response.Output.Write(oStringWriter.ToString());
                Response.Flush();
                Response.End();
                GridView1.AllowSorting = true; //恢复分页 GridView1.AllowPaging = true; //恢复排序
                GetDataALL(); //再次绑定 }
     
            }
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-11-281-1.html
    相关热词搜索: gridview excel