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

Export to Excel (ExcelML)

2 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stas
Top achievements
Rank 1
Stas asked on 23 Mar 2016, 04:10 PM

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 Answers, 1 is accepted

Sort by
0
Stas
Top achievements
Rank 1
answered on 24 Mar 2016, 01:55 PM

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

0
Accepted
Dilyan Traykov
Telerik team
answered on 25 Mar 2016, 02:56 PM
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.
Tags
GridView
Asked by
Stas
Top achievements
Rank 1
Answers by
Stas
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or