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

RadGrid Excel export and currency format

1 Answer 436 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 05 Oct 2011, 07:57 AM
Hi,
I have a small problem that irritates me.

In a radgrid I have currency columns format set to

DataFormatString

 

 

="{0:C2}

 


which in my case gives me output as 2.999,00 kr, 289,00 kr, etc.

Problem is that when I export radgrid to excel then above examples will be seen as two different formats in excel and I can't for example summarize a column since it is seen as two different formats, ex below

203,00
186,00
3.233,00 kr
137,00
213,00
157,00
173,00
546,00
751,00
1.750,00 kr
1.750,00 kr
150,00

Reason is that my excel is having another format for amounts >= 1000 kr which is 3 233,00 kr. So how to get amounts in my excel currency format when I export radgrid? Ex as below

203,00 kr
186,00 kr
3 233,00 kr
137,00 kr
213,00 kr
157,00 kr
173,00 kr
546,00 kr
751,00 kr
1 750,00 kr
1 750,00 kr
150,00 kr

I tried to change to DataFormatString="{0:####,## kr} in the radgrid but that solved not my problem.

Thx in advance!

Rgds,
Jesper

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Oct 2011, 02:44 PM
Hello Jesper,

Values modified with DataFormatString property are essentially string values. This is the the same as if you use String.Format(some value and format).
From this point on, you rely on Microsoft Excel to properly parse the formatted string as a numeric value. In some cases it does recognize it the value but in others the result is unexpected.
There are two common options:
- conditionally apply the desired format in code-behind. When exporting leave the values unformatted, otherwise format them with String.Format.
- handle the ExportCellFormatting event (or ItemCreated/ItemDataBound) and set the mso-number-format property to @. This will force Excel to recognize the value as text.

For more information, please examine the following topic:
Word/Excel export (HTML-based)

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Jesper
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or