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

Export two grids in two files

6 Answers 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Veteran
David asked on 22 Sep 2015, 03:49 PM

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

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 25 Sep 2015, 06:37 AM
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
0
David
Top achievements
Rank 1
Veteran
answered on 25 Sep 2015, 06:44 PM

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?

0
David
Top achievements
Rank 1
Veteran
answered on 02 Oct 2015, 12:11 PM
Pavlina? Any response?
0
Pavlina
Telerik team
answered on 05 Oct 2015, 08:02 PM
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
0
David
Top achievements
Rank 1
Veteran
answered on 06 Oct 2015, 04:18 PM

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?

0
Pavlina
Telerik team
answered on 07 Oct 2015, 01:51 PM
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
Tags
Grid
Asked by
David
Top achievements
Rank 1
Veteran
Answers by
Pavlina
Telerik team
David
Top achievements
Rank 1
Veteran
Share this question
or