爽的翻 2018-09-25 03:19 采纳率: 66.7%
浏览 554
已采纳

asp.net gridview 导出Excel 分页???

  • 这是我现在用的方法

    /// 导出方法
        /// </summary>
        /// <param name="GridView"></param>
        /// <param name="filename">保存的文件名称</param>
        private void ExportGridViewForUTF8(GridView GridView, string filename)
        {
    
            string attachment = "attachment; filename=" + filename;
    
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", attachment);
    
            Response.Charset = "UTF-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            Response.ContentType = "application/ms-excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
    
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView.RenderControl(htw);
    
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
    

    图片说明

  • 这是我用这个方法实现的效果

  • 现在我想让他把后面分页的5224条数据,全显示在一个Excel表里

  • 应该怎么写啊 大佬们
    *

  • 写回答

2条回答 默认 最新

  • 发个福福 2018-09-25 07:26
    关注
    如果你不想去掉网页的分页  可以向下面 加上前两句代码  重新从数据源查一遍数据 ,gridview 的属性allowpaging 设为false  不会影响网页分页
    
    
        private void ExportGridViewForUTF8(GridView GridView1, string filename)
    {
    
        GridView1.AllowPaging = false;
    
        bind();//重新为gridview 绑定数据
    
    
        string attachment = "attachment; filename=" + filename;
    
        Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", attachment);
    
        Response.Charset = "UTF-8";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        Response.ContentType = "application/ms-excel";
        System.IO.StringWriter sw = new System.IO.StringWriter();
    
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
    
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问下这个红框里面是什么文档或者记事本编辑器
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179