Multi grid export

5 posts, 0 answers
  1. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 01 Apr Link to this post

    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

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Apr Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 05 Apr in reply to Pavlina Link to this post

    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?

  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 07 Apr Link to this post

    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.
  6. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 08 Apr in reply to Pavlina Link to this post

    Thank you Pavlina
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017