一页中的两个网格视图。如何使用两个选项卡将点击按钮上的两个网格视图导出到一个Excel工作表,每个网格视图一个选项卡! [英] Two gridviews in one page. How to export both gridviews on a click of a button to one excel sheet using two tabs, one tab for each gridview!

查看:51
本文介绍了一页中的两个网格视图。如何使用两个选项卡将点击按钮上的两个网格视图导出到一个Excel工作表,每个网格视图一个选项卡!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Gridview。 GridView1和GridView2在一个页面上。但是,我想将两个gridviews导出到一个选项卡上的Gridview1和另一个选项卡上的GridView2上。这可能与我在下面实现的代码有关吗?

是否可以为GridView2的excel添加另一个选项卡?



I have two Gridviews. GridView1 and GridView2 on one page. However, i want to export both gridviews into an excel having Gridview1 on one tab and GridView2 on another tab. Is that possible with the code that i have implemented below?
Is it possible to add another tab to the excel for GridView2?

Protected Sub ExportAsExcel_Click(sender As Object, e As EventArgs) Handles ExportAsExcel.ClickResponse.Clear()
        Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment;filename=Export.xls")
        Response.Charset = ""
            Response.ContentType = "application/vnd.ms-excel"
            Using sw As New StringWriter()
                Dim hw As New HtmlTextWriter(sw)
                GridView1.RenderControl(hw)
                
                Dim style As String = ""
                Response.Write(style)
                Response.Output.Write(sw.ToString())
                Response.Flush()
                Response.End()
            End Using

    End Sub





我的尝试:



谷歌没有帮助。我甚至试图将GridView 2添加到代码中,但我在逻辑上陷入了这个问题。



What I have tried:

Google was no help. I even tried to add GridView 2 to the code but i am logically stuck in this matter.

推荐答案

使用当前的方法是不可能的,而是将你的两个gridview数据输入两个不同的数据表并使用OpenXML SDK导出它



参考使用C#和VB.Net将ASPSet中的DataSet DataTable导出到多个Excel表格(工作表)中[< a href =http://www.aspsnippets.com/Articles/Export-DataSet fundingTables-to-multiple-Excel-Sheets-Worksheets-in-ASPNet-using-C-and-VBNet.aspx\"target =_ blank title =新窗口> ^ ]



导出到Excel - 多个GridView到多个工作表 [ ^ ]
With current approach its not possible, instead get your two gridview data into two different datatable and using OpenXML SDK export it

Refer Export DataSet DataTables to multiple Excel Sheets (Worksheets) in ASP.Net using C# and VB.Net[^]

Export to Excel – Multiple GridView into Multiple Worksheet[^]


这篇关于一页中的两个网格视图。如何使用两个选项卡将点击按钮上的两个网格视图导出到一个Excel工作表,每个网格视图一个选项卡!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆