Pasting "13-1.1" into a cell sets it to " 36904"

4 posts, 0 answers
  1. Jannk
    Jannk avatar
    23 posts
    Member since:
    Jul 2014

    Posted 04 May 2015 Link to this post

    Hello,

    when I am  pasting  "13-1.1" into a cell, it sets the cell to " 36904".

    Cell formats I tried:

    sheet.Cells[row, columnIndex.Index].SetFormat(new CellValueFormat("@"));

    sheet.Cells[row, columnIndex.Index].SetFormat(CellValueFormat.GeneralFormat);

    Could you try to reproduce it and tell me, if its a bug?

    Jannik

  2. Anna
    Admin
    Anna avatar
    99 posts

    Posted 07 May 2015 Link to this post

    Hello Jannk,

    If you try doing the same in Excel, you will notice that the result is the date 13.01.2001 and the underlying number representation of this date is 36904. RadSpreadsheet, just as Excel does, parses the value 13-1.1 into a date, but doesn't apply the date format and this is why the result is 36904, instead of 13.01.2001. In other words, changing the value to a date is expected behavior when the culture of the machine is set to German.

    If you would like to avoid this behavior, both in Excel and RadSpreadsheet, you need to perform two steps:

    1. Set the format of the cell to text, either though code or through the UI, just as you did in the code you shared.
    sheet.Cells[row, columnIndex.Index].SetFormat(new CellValueFormat("@"));

    2. Enter in edit mode of the cell and only then paste the value. This way you avoid the paste command, which parses the value even before it reaches the cell. Instead of this, you will use the paste functionality of the cell editor, which will not attempt to parse it. When you exit edit mode, the value will be parsed, but the text format which we set in step 1. will prevent it from parsing to a date.

    I hope this explanation will be helpful and suitable for your scenario. Please, let me know if you have further questions or concerns.

    Regards,
    Anna
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. DevCraft banner
  4. Jannk
    Jannk avatar
    23 posts
    Member since:
    Jul 2014

    Posted 12 May 2015 in reply to Anna Link to this post

    Hello Anna,

    thanks for the reply.

    Is there any way to avoid this behaviour? I would love to see it always act like I am in edit mode,.

    Best regards

    Jannik

  5. Anna
    Admin
    Anna avatar
    99 posts

    Posted 13 May 2015 Link to this post

    Hello,

    Unfortunately there is no way to avoid this particular behavior other than using the steps I described or changing the culture of the machine (for example to English - United States).

    Regards,
    Anna
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top