Disabling the formula functionalities

5 posts, 0 answers
  1. Thomas
    Thomas avatar
    2 posts
    Member since:
    Mar 2013

    Posted 22 Apr 2013 Link to this post


    I was looking for a way to disable the formula capabilities of the control is this possible?(e.g =SUM(A+B)).
    This without the need to disable the cells.

    Kind regards,

  2. Boryana
    Boryana avatar
    330 posts

    Posted 23 Apr 2013 Link to this post

    Hello Thomas,

    Thank you for contacting us.

    A cell will display its literal content if its format is set to Text. The following snippet assigns the cell A1 in the active worksheet a formula value and sets its format to Text. As a result,  A1 will display =SUM(1, 2, 3) instead of 6

    CellSelection cellA1 = this.radSpreadsheet.ActiveWorksheet.Cells[0, 0];
    cellA1.SetValue("=SUM(1, 2, 3)");
    cellA1.SetFormat(new CellValueFormat("@"));

    If you would like to apply the Text format to all entered values in a worksheet, feel free to use the following sample code:
    Worksheet activeWorksheet = this.radSpreadsheet.ActiveWorksheet;
    activeWorksheet.Cells[activeWorksheet.UsedCellRange].SetFormat(new CellValueFormat("@"));

    I hope you will find my answer helpful. Let me know if you have further questions.

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Marcus
    Marcus avatar
    40 posts
    Member since:
    Aug 2012

    Posted 07 Nov 2017 in reply to Boryana Link to this post

    Hello Boryana,

    after a long time I want to reactivate this thread.

    For text-cells I use your following hint:

    cell.SetFormat(new CellValueFormat("@"));

    This all works fine but some values for "wert" leads to an strange result:

    If "wert" is "1900", "1900" will be displayed but if "wert" is "1900-01" then "1", if "1900-02" then "32", ..., "1900-06" then "153" are displayed. Although the cell is in text format, here the table seems to evaluate the number of days since 1899-31-12 (on a German Windows 10).

    I am using version 2017.2.503.45 of the spreadsheet.dll

    How can I prevent this behavior.

    Thanks in advance



  4. Anna
    Anna avatar
    123 posts

    Posted 08 Nov 2017 Link to this post

    Hello Marcus,

    You can stop this behavior by setting the cell format before setting the value like so:

    cell.SetFormat(new CellValueFormat("@"));

    The reason why this works is that with this ordering when the time comes to parse the input, RadSpreadsheet will already know that the preferred result is a text value. Otherwise it recognizes a date and parses the value as such. Then when the text format is applied after the parsing, it strips the date format and the result is 1, 32 and 153.

    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Marcus
    Marcus avatar
    40 posts
    Member since:
    Aug 2012

    Posted 09 Nov 2017 in reply to Anna Link to this post

    Hello Anna,

    thanks. Sometimes the solution is so simple.



Back to Top