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

Radgridview: Export to Excel question

7 Answers 1005 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Evan
Top achievements
Rank 1
Evan asked on 17 Oct 2018, 03:13 PM

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

 

 

7 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 18 Oct 2018, 08:17 AM
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.
0
Evan
Top achievements
Rank 1
answered on 18 Oct 2018, 03:30 PM

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!

 

0
Dimitar
Telerik team
answered on 19 Oct 2018, 10:37 AM
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 and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mohsen
Top achievements
Rank 1
answered on 30 Nov 2019, 12:42 PM

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!

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Dec 2019, 01:15 PM

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.
0
Mohsen
Top achievements
Rank 1
answered on 03 Dec 2019, 06:00 AM

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.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Dec 2019, 11:07 AM

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.
Tags
GridView
Asked by
Evan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Evan
Top achievements
Rank 1
Mohsen
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or