How do I force a cell format to text?

3 posts, 0 answers
  1. Marc
    Marc avatar
    2 posts
    Member since:
    Jul 2013

    Posted 13 Sep 2014 Link to this post

    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. Anna
    Anna avatar
    99 posts

    Posted 15 Sep 2014 Link to this post

    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("@"));

    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.

    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.
  3. Marc
    Marc avatar
    2 posts
    Member since:
    Jul 2013

    Posted 15 Sep 2014 in reply to Anna Link to this post

    Hi Anna,

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

Back to Top