Keep Grouping and Filtering Settings When Exporting WinForms RadGridview to Excel

3 posts, 0 answers
  1. jgill
    jgill avatar
    116 posts
    Member since:
    Jul 2005

    Posted 18 Dec 2008 Link to this post

    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. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 20 Dec 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 20 Dec 2008 Link to this post

    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.
Back to Top