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

Exporting grid to excel

3 Answers 343 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 01 Dec 2017, 03:05 PM
I've created a datatable using the following query:
select str(-abs(100),10,2) as crash
(a negative number cast to string)

When I use this datatable in a grid and export it to excel, I'll get the folowwing error:
We found a problem with this formula. Try clicking Insert Function on the Formulas tab to fix it.\n\nNot trying to type a formula? When the first character is an equal (=) or minus (-) sign, RadSpreadsheet thinks it is a formula. For example, when you type =1+1 the cell shows 2.

I've implemented the workarround in https://www.telerik.com/forums/output-to-excel-error
(The cell has the Format attribute set to "@")
This works for regular strings starting with a dash, but not working for the specific situation described before.

3 Answers, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 06 Dec 2017, 01:43 PM
Hi Nick,

Setting the DataFormatString property of GridColumn to "{0:@}" will produce the required behavior.
<telerik:GridBoundColumn ... DataFormatString="{0:@}"></telerik:GridBoundColumn>

Please check out the sample I've attached that demonstrates this scenario, to see if that works for you.

Kind Regards,
Attila Antal
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 07 Dec 2017, 02:26 PM

Hi Attila,

Thanks, this solved the problem. 

Below my solution using the GridColumnCreated event

protected void ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column is GridBoundColumn boundColumn)
    {
        if (boundColumn.DataType == typeof(string))
            boundColumn.DataFormatString = "{0:@}";
    }
}
0
Attila Antal
Telerik team
answered on 07 Dec 2017, 02:45 PM
Hi Nick,

I am glad to hear the problem has been solved!

Also, I would like to thank you for sharing your method with the community, well done!

Kind Regards,
Attila Antal
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Nick
Top achievements
Rank 1
Share this question
or