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

Export format not respecting DataFormatString

3 Answers 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 17 Jan 2014, 08:11 PM
Hello,

We are currently using the export feature of the GridView. Either with grid.ToText() or grid.Export({...}) it seems that the DataFormatString of the GridViewDataColumn isn't applying to the export, only to the view on the grid. Example a decimal number appears as 15 in the grid, but the export is 15.00.

Is this expected? Is there a workaround to get the grid to export the data using the same format it uses for display?

Extra info:
Column: DataType = typeof(decimal?);
Column: DataFormatString = "{0:N0}";
Backing data is decimal?

Thank you,
Patrick

3 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 20 Jan 2014, 08:06 AM
Hello Patrick,

With Q3 2013 official version we introduced a new event InitializingExcelMLStyles which will be raised when exporting with ExportFormat.ExcelML. Using it you can define a Style for the exported data and to use NumberFormat in order to achieve your requirements. Please check this help topic for more information. Also, you can find Customizing ExcelML export demo useful.

Let us know if you have additional questions.

Regards,
Yordanka
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Patrick
Top achievements
Rank 1
answered on 21 Jan 2014, 03:13 PM
Thank you for the info on the ExcelML export feature. We were able to handle the formatting with very little change like this:

private void FormatExportingElement(GridViewElementExportingEventArgs e)
{
    if (e.Value is decimal)
    {
        decimal d = (decimal)e.Value;
 
        //special case for exporting - forces a retain of format
        var gvdc = e.Context as GridViewBoundColumnBase;
        if (gvdc != null && !string.IsNullOrEmpty(gvdc.DataFormatString))
        {
            e.Value = d.ToString(gvdc.DataFormatString);
            return;
        }
    }
}

-Patrick
0
Yordanka
Telerik team
answered on 21 Jan 2014, 03:20 PM
Hi Patrick,

I am glad to hear you have found an applicable solution. Let us know if you have additional questions.

Regards,
Yordanka
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Patrick
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or