• [转]多个gridview怎么导出同一个Excel文档?


    有三个gridview :A  B  C
    B C 是根据 A查出来的 
    现在想把它们都导出到一个EXCEL里面

       private void GridViewToExcel()
        {
            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
            Response.ContentEncoding = System.Text.Encoding.UTF7;
            Response.ContentType = "application/ms-excel";
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            gvSelectorder.RenderControl(oHtmlTextWriter);
            Response.Output.Write(oStringWriter.ToString());
            Response.Flush();
            Response.End();
        }

    这样写只能导出一个   如何才能全部导出 在一个excel里面?答案如下:

    1、你把两个GridView放在一个div里,比如这样

    1 <div runat="server" id="divExport">
    2   <gridview1 .....>
    3   <gridview2 .....>
    4 </div>

    2、然后后台 gvSelectorder.RenderControl(oHtmlTextWriter); 这句改成 divExport.RenderControl(oHtmlTextWriter); 试一下

  • 相关阅读:
    冒泡排序
    Objective-C 命名规范
    时间轴的制作
    CocoaPods 哪些事
    消息转发机制入门篇
    架构
    算法学习
    AutoLayout自动布局
    网络学习
    HDU 3832 Earth Hour (最短路)
  • 原文地址:https://www.cnblogs.com/seasons1987/p/3131527.html
Copyright © 2020-2023  润新知