GridView Excel Exporting

1 Answer 27 Views
GridView
Brie
Top achievements
Rank 1
Brie asked on 30 Aug 2021, 05:02 PM

We are working on implementing exporting to Excel in our application's radgridview - we used this tutorial: https://docs.telerik.com/devtools/wpf/controls/radgridview/export/generic/export and it works with some errors. 

When trying to create a file with an .xls file extension, we get an error of "The format and extension of this file do not match". How do we fix this? 

When saving, the file extension appears twice after the "Excel files" in the save dialog. Why is this? Is this potentially causing issues? 

Also, we would like to change the formatting of the file on export - for example, freezing the headers, automatically setting the column widths, etc - what is the best way to set these properties?

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 31 Aug 2021, 02:33 PM

Hello Brie,

Thank you for the provided images.

The error you received has been discussed in this forum thread: RadGridView Export is having issue with the generated file. As explained by my colleague, it is recommended to use the new ExportToXlsx method to resolve this. This method also allows for more customizations and styling via the exporting events. The first event("ElementExportingToDocument") fires when the ExportToXlsx method is called. And if the tunnel event is not canceled, the ElementExportedToDocument event fires. This life cycle changes the items when exported to an Excel file.

You can also have a look at this article which explains the warning: Warning message when opening the excel file.

Alternatively, you can also use the ExportToWorkbook method which allows you to further customize the exported document - such as formatting, column widths, etc.

As for the file extension, there appears to be a formatting issue in our documentation which has modified the filter string. For it to work as expected, you need to define it as follows:

Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel")

Please note the additional * symbols.

Please let me know if you find this information helpful in achieving the desired result.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Brie
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or