Export to Excel (ExcelML)

3 posts, 1 answers
  1. Stas
    Stas avatar
    5 posts
    Member since:
    Apr 2014

    Posted 23 Mar Link to this post

    When export grid to Excel (using ExcelML format) all numbers are exported as text.

    Is there a way to export numbers as formatted  numerik values?

     

    Thank you

  2. Stas
    Stas avatar
    5 posts
    Member since:
    Apr 2014

    Posted 24 Mar Link to this post

    I found the way around.

    When numerik column has DataFormatString it is exported as text. So I create another grid copy there columns without DataFormatString, export new grid to excel, than open excel and apply format to columns in excel file

  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    370 posts

    Posted 25 Mar Link to this post

    Hello Stas,

    I'm glad to hear that you found a solution to your problem. I would, however, like to suggest another approach using the ElementExporting event so that you do not have to go trough the trouble of creating a copy of your grid.

    For example, provided you have a GridView with a name of clubsGrid and a StadiumCapacity column of type double that has a DataFormatString="{}{0:F3}", you can parse the values as follows:

    void clubsGrid_ElementExporting(object sender, GridViewElementExportingEventArgs e)
    {
        if (e.Element == ExportElement.Cell)
        {
            var column = e.Context as GridViewDataColumn;
            if (column.Header.ToString() == "StadiumCapacity")
            {
                e.Value = double.Parse(e.Value.ToString());
            }
        }
    }

    Please let me know if this approach would work for you. I would also be happy to answer any further questions or concerns you might have.

    Regards,
    Dilyan Traykov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top