Radgridview: Export to Excel question

8 posts, 1 answers
  1. Evan
    Evan avatar
    14 posts
    Member since:
    Apr 2018

    Posted 17 Oct 2018 Link to this post

    Hi- I'm having trouble with exporting grid contents to Excel- using winforms radgridview version 2018.1.220.40 in vb.net.  (Hopefully this is a stupid question but I've spent an hour looking through documentation and I think I'm missing something.)  I found the code snippet below in the documentation, but getting the error 

    gridViewExport is not defined, and gridviewExportOptions not defined...  

    I'm assuming that gridViewExport is supposed to be my radgridview object, but when I sub in the name of mine, it says 'export' is not a member of RadGridView... 

    Can you advise?    Thanks very much. 

    -----------------------------------------

    https://docs.telerik.com/devtools/wpf/controls/radgridview/export/export

        Private Sub btnExport_Click(sender As Object, e As RoutedEventArgs)
            Dim extension As String = "xls"
            Dim dialog As New SaveFileDialog() With {
             .DefaultExt = extension,
             .Filter = String.Format("{1} files (.{0})|.{0}|All files (.)|.", extension, "Excel"),
             .FilterIndex = 1
            }
            If dialog.ShowDialog() = True Then
                Using stream As Stream = dialog.OpenFile()
                    gridViewExport.Export(stream, New GridViewExportOptions() With {
                     .Format = ExportFormat.Html,
                     .ShowColumnHeaders = True,
                     .ShowColumnFooters = True,
                     .ShowGroupFooters = False
                    })
                End Using
            End If
        End Sub

     

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2913 posts

    Posted 18 Oct 2018 Link to this post

    Hi Evan,

    This is the WinForms forum. Are you using the WinForms grid or the WPF one? 

    The gridViewExport is not the grid this is a separate object that is used for export only. The correct object for the WinForms suite is available in the following article: Export to Excel

    I am looking forward to your reply. 

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Evan
    Evan avatar
    14 posts
    Member since:
    Apr 2018

    Posted 18 Oct 2018 in reply to Dimitar Link to this post

    Yes- Winforms- thanks for clarifying.   

    I had found the article you linked, but was missing the reference in my project to enable it.  (Seems like I run into that alot- Telerik has great comprehensive documentation and great support, but I sometimes have trouble tracing back from the methods to the required references/imports namespaces- I'm sure I'm not reading enough though.)    Anyway, when I got the references right- it works great.

    Thanks!

     

  4. Dimitar
    Admin
    Dimitar avatar
    2913 posts

    Posted 19 Oct 2018 Link to this post

    Hi Evan,

    I am glad that this works now. Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Mohsen
    Mohsen avatar
    3 posts
    Member since:
    Nov 2019

    Posted 30 Nov 2019 Link to this post

    Hi

    I have a very annoying problem with exporting to excel

    I built an radGridView with multi-header style

    when I export the radGridView to Xlsx file, some of headers are ok and some of them not!

    I mean some of headers merge with other parts and its not good, I added my exported file.

    please help me!

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 02 Dec 2019 Link to this post

    Hello, Mohsen,

    Following the provided information, I have prepared a sample project with RadGridView that uses a ColumnGroupsViewDefinition. The exported file looks OK. It was necessary to handle the SpreadExportRenderer.WorkbookCreated event and to call the AutoFitWidth method for each call so that the header text would fit in the available space:

    I have attached my sample project for your reference. Please give it a try and see how it works on your end.

    If you are still experiencing any further difficulties, it would be greatly appreciated if you specify the exact steps how to reproduce the problem. Thus, we would be able to assist you further. Thank you in advance.

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Mohsen
    Mohsen avatar
    3 posts
    Member since:
    Nov 2019

    Posted 03 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Dear Dess

    I checked your project and realize that we are not on the same page.

    my problem is, when I set exact same name for groups and extract it to excel, it remove groups with same names, and the excel file become a mess.

    for more information,I changed name of all groups to 'SameName' and send you image of grid and excel file, they are different and exported excel is wrong

    you can see the difference between images.

  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 03 Dec 2019 Link to this post

    Hello, Mohsen, 

    Thank you for providing the clarification. I was able to replicate the undesired behavior when the GridViewColumnGroups have exactly the same names. 

    However, note that the GridViewColumnGroup is not associated with any real column in the grid. Hence, its text should be unique in order to be distinguished when accessing it later. The export functionality also relies on the specified text for the column group to find it and if more than one column groups have the same header text, you may obtain unexpected results.  

    Please make sure that you use unique names for the column groups.

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top