Export format not respecting DataFormatString

4 posts, 0 answers
  1. Patrick
    Patrick avatar
    43 posts
    Member since:
    Jan 2013

    Posted 17 Jan 2014 Link to this post

    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
  2. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 20 Jan 2014 Link to this post

    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 >>
  3. DevCraft banner
  4. Patrick
    Patrick avatar
    43 posts
    Member since:
    Jan 2013

    Posted 21 Jan 2014 Link to this post

    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
  5. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 21 Jan 2014 Link to this post

    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 >>
Back to Top