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

Force string format in export to Excel

2 Answers 430 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Miles
Top achievements
Rank 1
Miles asked on 28 Jun 2013, 11:51 AM

I'm currently exporting to Excel a RadGrid and I have some cells that have the text "1 / 10" meaning that they had 1 hour used for 10 units. When this gets to Excel, it thinks the cell is a date, so it changes the cell to be January-10 which is not what I'm wanting.

I've gone the other direction before (changing a string to a number/date by setting the cell style's mso-number-format property) but I've never had the issue where I needed to make Excel keep the cell as a string and not try to change the format.

How do I do this? I've tried adding a apostrophe to the beginning of the cell text:

e.Cell.Text = String.Format("'{0}", e.Cell.Text);
but that seems to just make Excel display two apostrophe's at the start of the cell.

I'm using an older version of the Grid (2010.2.929.40)

2 Answers, 1 is accepted

Sort by
0
Miles
Top achievements
Rank 1
answered on 02 Jul 2013, 01:22 PM
bump...
0
Kostadin
Telerik team
answered on 03 Jul 2013, 06:33 AM
Hello Miles,

In your case the excel automatically format the cells value to Date format so by using the mso-number-data attribute you could explicitly change the format to string. I prepared a small sample and attached it to this thread. I hope this helps.

Regards,
Kostadin
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Miles
Top achievements
Rank 1
Answers by
Miles
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or