Export two grids in two files

7 posts, 0 answers
  1. David
    David avatar
    274 posts
    Member since:
    Mar 2014

    Posted 22 Sep 2015 Link to this post

    Ideally, i would like to export my grids to one file, but seems i will need to create wrapper grid around my grids and it would not fit my scenario. Second option for is to create two separate export files. However, i am getting only second file saved. Here is my approach:

    Export(grid, subName, strCenterHeader, alternateText)

    Export(grid2, subName2, strCenterHeader2, alternateText)

    Protected Sub Export(ByVal grid As RadGrid, _
                             ByVal subName As String, _
                             ByVal strCenterHeader As String, _
                             ByVal alternateText As String)

            grid.ExportSettings.FileName = TredisSession.Current.Project.ProjectName.Replace(" ", "_") & "_" & subName & "_Data"

            grid.ExportSettings.ExportOnlyData = True
            grid.ExportSettings.OpenInNewWindow = True
            grid.ExportSettings.UseItemStyles = True

            Select Case alternateText

                Case "HTML"
                    grid.ExportSettings.Excel.Format = GridExcelExportFormat.Html
                    grid.MasterTableView.ExportToExcel()

                Case "ExcelML"
                    grid.ExportSettings.Excel.Format = DirectCast([Enum].Parse(GetType(GridExcelExportFormat), alternateText), GridExcelExportFormat)
                    grid.MasterTableView.ExportToExcel()

                Case "Xlsx"
                    grid.ExportSettings.Excel.Format = DirectCast([Enum].Parse(GetType(GridExcelExportFormat), alternateText), GridExcelExportFormat)
                    grid.MasterTableView.ExportToExcel()

                Case "PDF"

                    Dim footerMiddleCell As String = "<?page-number?>"

                    ' to get lanscape orientation
                    grid.ExportSettings.Pdf.PageHeight = Unit.Parse("200mm")
                    grid.ExportSettings.Pdf.PageWidth = Unit.Parse("500mm")

                    grid.ExportSettings.Pdf.PageHeader.MiddleCell.Text = strCenterHeader
                    grid.ExportSettings.Pdf.PageHeader.MiddleCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Center

                    grid.ExportSettings.Pdf.PageFooter.MiddleCell.Text = footerMiddleCell
                    grid.ExportSettings.Pdf.PageFooter.MiddleCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Center

                    grid.MasterTableView.ExportToPdf()

                Case "Doc"
                    grid.MasterTableView.ExportToWord()

                Case "CSV"
                    grid.MasterTableView.ExportToCSV()

            End Select

        End Sub

    Thank you

  2. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 25 Sep 2015 Link to this post

    Hi,

    I suggest you examine the project attached here: https://github.com/telerik/aspnet-sdk/tree/master/Grid/ThreeRadGridsExport where a possible realization of the requested scenario is illustrated. The code in the example is configured in such way that the user has the option to export the grids in one spreadsheet or in different ones.

    Regards,
    Pavlina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. David
    David avatar
    274 posts
    Member since:
    Mar 2014

    Posted 25 Sep 2015 in reply to Pavlina Link to this post

    This is interesting approach, but doesn't work for hierarchical grid. Also, ​though it is possible to make this approach work for this case it will export whole grid, while i am interested to export only parts that were expanded (what you see is what you export).

     So, coming back to my original code, can you explain to me why sequential calls for export result in only one (second) exported file?

  4. David
    David avatar
    274 posts
    Member since:
    Mar 2014

    Posted 02 Oct 2015 Link to this post

    Pavlina? Any response?
  5. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 05 Oct 2015 Link to this post

    Hello,

    Even for hierarchy grid you can still use the approach from the pointed sdk example: https://github.com/telerik/aspnet-sdk/tree/master/Grid/ThreeRadGridsExport, you only need to traverse all detail items as describe in the following help article and export the desired data:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/traversing-detail-tables
     
    Regarding your second question - you cannot perform multiple export requests sequentially. When the second request is performed the first one is canceled, therefore you get only second exported file.

    Regards,
    Pavlina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. David
    David avatar
    274 posts
    Member since:
    Mar 2014

    Posted 06 Oct 2015 in reply to Pavlina Link to this post

    Thank you Pavlina, that seems to be working.

    Couple of questions though:

    1) Seems footer is not getting exported (total record)

    2) What can i do to export more than one table to pdf?

  7. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 07 Oct 2015 Link to this post

    Hello,

    For your first question you can use the same approach, access the footer item and add it to the document after you add the data. The code should look like the one snippet below:
    GridFooterItem footerItem = grid.MasterTableView.GetItems(GridItemType.Header)[0] as GridFooterItem;
     
            for (int i = 2; i < footerItem.Cells.Count; i++)
            {
                singleTable.Cells[i - 1, row].Value = footerItem.Cells[i].Text;
            }

    About your second question you can follow the implementation shown in this code library:
    http://www.telerik.com/support/code-library/export-multiple-radgrids-in-single-pdf-excel-file  

    Regards,
    Pavlina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top