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

Keep Grouping and Filtering Settings When Exporting WinForms RadGridview to Excel

2 Answers 285 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jgill
Top achievements
Rank 1
jgill asked on 18 Dec 2008, 10:31 PM

I wanted to know if there is a way to retain grouping, sorting, and filteringg set in a WinForms RadGrid when exporting to Excel.

 

I have a WinForms application that uses the RadGridview to allow users to sort and group items, however currently when they export the data to Excel the data only exports when they do not have any items grouped.

 

I wanted to know how I could allow them to use the RadGridview to group, sort, and filter the items then keep those settings when the data is exported to Excel.  Are there some settings I need to enable in the Gridview itself or modifications that need to be made to the Export sub-routine to allow this.


This is the code that is run when a user clicks the export to Excel button:

 Private Sub btnExportToExcel_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles btnExportToExcel.Click  
        If SaveFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then 
            If (Not SaveFileDialog.FileName.Equals(String.Empty)) Then 
                Dim file As New FileInfo(SaveFileDialog.FileName)  
                If file.Extension.Equals(".xls"Then 
                    Export(SaveFileDialog.FileName)  
                Else 
                    MessageBox.Show("Invalid file type")  
                End If 
            Else 
                MessageBox.Show("Please enter a file name.")  
            End If 
 
            Me.btnExportToExcel.Enabled = True 
        End If 
 
    End Sub 
    Private Sub Export(ByVal filepath As String)  
        Me.btnExportToExcel.Enabled = False 
        Dim exporter As New ExportToExcelML()  
        Dim exportThemeColors As Boolean = True 
        exporter.RunExport(Me.grdData, filepath, ExportToExcelML.ExcelMaxRows._65536, exportThemeColors)  
        Me.btnExportToExcel.Enabled = True 
        MessageBox.Show("Exporting Finished.")  
    End Sub 

2 Answers, 1 is accepted

Sort by
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 20 Dec 2008, 11:05 AM
jgill,

Grouped grids currently do not export to excel ML - this is a known bug in 2008Q3 / Q3 SP1. According to telerik it will be resolved in the next SP.

If the bug is fixed, you can select whether to export filtered rows or not. Plus you can select if you want rows to be formatted according to grid settings.

However, since not all functions of the gridView have direct equivalents in excel, you cannot expect the export to be 1:1 the same.

Regards
Erwin
0
Martin Vasilev
Telerik team
answered on 20 Dec 2008, 11:59 AM
Hi jgill,

Thank you for contacting us.

The ExcelML method exports data with current filtering and sorting. This functionality is built in and there is no need to do anything to enable it. When the RadGridView is grouped, the export should populate the excel file as a nongrouped data. This is because MS Excel does not support grouping in the same way as data grid.

Erwin is correct, however, that with current version of RadGridView we have a known issue and it does not export any data from grouped grid. This has already been fixed and will be available in the next SP2 release in the January 2009. Please, excuse us for the inconvenience.

If you have other questions, do not hesitate to contact me again.

 
Best wishes,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
jgill
Top achievements
Rank 1
Answers by
erwin
Top achievements
Rank 1
Veteran
Iron
Martin Vasilev
Telerik team
Share this question
or