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

Format text as real text in Excel export

2 Answers 370 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 20 Aug 2014, 03:58 PM
Hi,
I'm using the example http://demos.telerik.com/silverlight/#SpreadProcessing/RadGridViewIntegration to implement an Excel export for my RadGridView.

How can I format a string to a text column in Excel? I have a value of "001" and if I use

worksheet.Cells[currentRowIndex, currentColumnIndex].SetValue((string)value);

it uses a NumberCellValue internally (because it thinks that "001" is a number") and formats the cell as a number instead of text and puts "1" instead of "001" into the Excel file.

Since the constructor of TextCellValue is internal (I have no clue why) I can't even create an instance of this type. CellValueFactory creates a NumberCellValue, too. So I'm basically stuck here. Is there any way for FORCING my cell to use the string as it is and format it as text in Excel so that I can have the "001" as the cell value?

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Demirev
Telerik team
answered on 21 Aug 2014, 11:39 AM
Hello Thomas,

All it needs to be done so the cell is formatted as text is to set the NumberFormat of the cell to be text. It can be achieved using the following line of code:
worksheet.Cells[currentRowIndex, currentColumnIndex].SetFormat(new CellValueFormat("@"));

I suggest you to set the format on the whole range that will be formatted as text, because it will work faster compared to setting each cell the same format.

This article describes how to use the Number Formatting.

If you have any further questions, please do not hesitate to contact us again.

Regards,
Nikolay Demirev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Thomas
Top achievements
Rank 1
answered on 22 Aug 2014, 05:59 AM
Thanks, that was just what I needed :-).
Tags
SpreadProcessing
Asked by
Thomas
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or