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

How do I force a cell format to text?

2 Answers 896 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 13 Sep 2014, 09:35 AM
I write content to a cell that is by default interpreted as a date.
But I want it treated as plain text.
How do I do this? The CellValueFormat constructor wants a format string; but there is no format string for this case.

2 Answers, 1 is accepted

Sort by
0
Anna
Telerik team
answered on 15 Sep 2014, 11:56 AM
Hi Marc,

The format string which will help the value be interpreted as text is "@", as it is used in the following snippet:

CellSelection selection = this.radSpreadsheet.ActiveWorksheet.Cells[0, 0];
 
selection.SetFormat(new CellValueFormat("@"));
selection.SetValue("1/1/2013");

The reason why the format is applied before the value is set is that if you do it the other way around, you will get the numeric value of the date (41276), instead of the string you entered (1/1/2013), which is consistent with the behavior of Excel.

Regards,
Anna
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
Marc
Top achievements
Rank 1
answered on 15 Sep 2014, 01:14 PM
Hi Anna,

Thank you. This is indeed working. I had it the wrong way around (formatting after setting value).

Cheers
Marc
Tags
SpreadProcessing
Asked by
Marc
Top achievements
Rank 1
Answers by
Anna
Telerik team
Marc
Top achievements
Rank 1
Share this question
or