Using Telerik Export the data grid value into excel.

1 Answer 4 Views
GridView
John
Top achievements
Rank 1
Iron
Iron
Iron
John asked on 01 Sep 2025, 09:48 AM
Summarize the problem:  In the WPF grid, data is displayed using value converters (IValueConverter). When exporting with TelerikDataGrid.Export(), Telerik uses the raw bound values instead of the converted display values. This causes a mismatch: what you see in the grid is different from what appears in the exported Excel file.

Tried Method: 
Identified the root cause of the issue, the grid shows converted values (via IValueConverter). 
But after export uses raw bound values, will exported.  I need to export the Grid displayed value into the Excel.

M_DataGrid_ElementExporting

private void M_DataGrid_ElementExporting(object sender, Telerik.Windows.Controls.GridViewElementExportingEventArgs e)
        {
            if (e.Element == Telerik.Windows.Controls.ExportElement.Cell)
            {
                var cellExportingArgs = e as GridViewCellExportingEventArgs;

                if (e.Context is Telerik.Windows.Controls.GridViewDataColumn dataColumn)
                {
                    var col = e.Context as Telerik.Windows.Controls.GridViewDataColumn;
                    if (col != null && col.UniqueName == "MomentOfInertia")
                    {

                        var binding = dataColumn.DataMemberBinding;
                        var propertyValue = TelerikDataVis_Doc.GetPropertyValue(e.DataContext, binding.Path.Path);
                        if (binding != null)
                        {
                            object rawValue = e.Value;

                            if (binding.Converter != null)
                            {
                                rawValue = binding.Converter.Convert(
                                    propertyValue,
                                    typeof(string),
                                    binding.ConverterParameter,
                                    System.Globalization.CultureInfo.CurrentCulture);
                            }

                            if (!string.IsNullOrEmpty(binding.StringFormat))
                            {
                                e.Value = string.Format(binding.StringFormat, rawValue);
                            }
                            else
                            {
                                e.Value = rawValue?.ToString();
                            }
                        }
                    }
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 Sep 2025, 06:13 AM

Hello John,

This behavior occurs because of how the data engine of RadGridView works. Basically, if you use IValueConverter with the DataMemberBinding of the columns, the converter value will be used only as a display value. All other data operations (sorting, filtering, etc.) will use the raw value. This includes the export of the data too.

To achieve your requirement, you can use the ElementExporting event and adjust the final value, as you are already doing.

If you use the ExportToXlsx method (which is the recommended one), you can use the ElementExportingToDocument event.

Regards,
Martin Ivanov
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
John
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or