This is a migrated thread and some comments may be shown as answers.

Multi grid export

4 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Iron
Iron
Veteran
David asked on 01 Apr 2016, 07:50 PM

I currently able to export multiple grids to excel in one file. Problem is that me superiors would like it to be prettier.

Is there a way to export multi grids in html format? Please help!

My current export code is this:

                   Dim gridControlsFound As New List(Of RadGrid)()

                    gridControlsFound.Add(grdBCA_Assumptions_TravelDemand)
                    gridControlsFound.Add(grdBCA_Assumptions_StartupCosts)
                    gridControlsFound.Add(grdBCA_Assumptions_AnnualCosts)

                    ExportMultiGrid(gridControlsFound, "GrantReport")

Private Sub ExportMultiGrid( _
                            ByVal gridControlsFound As List(Of RadGrid), _
                            ByVal FileName As String)

        Dim tableXLS As New xls.Table()
        Dim ExportInSingleSpreadsheet As Boolean = True

        For Each grid As RadGrid In gridControlsFound
            grid.AllowPaging = False
            grid.CurrentPageIndex = 0
            'grid.Rebind()
            GenerateTable(grid, tableXLS)
        Next

        If ExportInSingleSpreadsheet = True Then
            [structure].Tables.Add(tableXLS)
        End If

        Dim renderer As New xls.XlsBiffRenderer([structure])
        Dim renderedBytes As Byte() = renderer.Render()
        Response.Clear()
        Response.AppendHeader("Content-Disposition:", "attachment; filename=" & FileName & ".xls")
        Response.ContentType = "application/vnd.ms-excel"
        Response.BinaryWrite(renderedBytes)
        Response.[End]()

    End Sub

 

 Private Sub GenerateTable(grid As RadGrid, ByRef singleTable As xls.Table)

        Dim ExportInSingleSpreadsheet As Boolean = True

        If ExportInSingleSpreadsheet = False Then
            singleTable = New xls.Table(grid.ID)
            row = 1
            col = 1
        Else
            If Not isFirstItem Then
                row += 1
            Else
                isFirstItem = False
            End If
        End If

         For i As Integer = 0 To grid.Columns.Count - 1

            If grid.Columns(i).HeaderText.Length = 1 Then
                If grid.Columns(i).UniqueName = "Discount1" Then
                    singleTable.Cells(i + 1, row).Value = txbDiscountRate_1.Text & "% discount rate ($ mil.)"
                ElseIf grid.Columns(i).UniqueName = "Discount2" Then
                    singleTable.Cells(i + 1, row).Value = txbDiscountRate_2.Text & "% discount rate ($ mil.)"
                Else
                    singleTable.Cells(i + 1, row).Value = grid.Columns(i).HeaderText
                End If
            Else
                singleTable.Cells(i + 1, row).Value = grid.Columns(i).HeaderText
            End If

        Next

        row += 1

        For Each item As GridDataItem In grid.MasterTableView.Items
            For Each column As GridColumn In grid.Columns
                singleTable.Cells(col, row).Value = item(column.UniqueName).Text
                col += 1
            Next
            col = 1
            row += 1
        Next

        If ExportInSingleSpreadsheet = False Then
            [structure].Tables.Add(singleTable)
        End If

    End Sub

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 04 Apr 2016, 02:39 PM
Hi,

To export multiple grids you can set FileExtension to html and use the approach presented in one of the following code libraries:
http://www.telerik.com/support/code-library/export-multiple-radgrids-in-single-pdf-excel-file#714450 
http://www.telerik.com/support/code-library/export-hierarchical-grid 

Regards,
Pavlina
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 05 Apr 2016, 01:46 PM

Pavlina,

  Thank you for the links, however i am asking for another thing.

   I need help to export to excel multiple grids in one file while preserving style of the grid

   Can you suggest solution?

0
Pavlina
Telerik team
answered on 07 Apr 2016, 03:12 PM
Hello,

You could review the following example which demonstrates how to export multiple grids in a single excel file and on separate spreadsheets:
https://github.com/telerik/aspnet-sdk/tree/master/Grid/ThreeRadGridsExport

Only keep in mind that you should set cell styles manually using the properties from the ExportStyles table in the article below. But before that you need to access the items in the grid which styles you want to change:
http://docs.telerik.com/devtools/aspnet-ajax/controls/export-infrastructure#structure (go to Export Styles table)

Please give it a try and let me know if I could provide you any further assistance.

Regards,
Pavlina
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 08 Apr 2016, 04:23 PM
Thank you Pavlina
Tags
Grid
Asked by
David
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Pavlina
Telerik team
David
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or