silevis / reactgrid

Add spreadsheet-like behavior to your React app

Home Page:https://reactgrid.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Copying from excel results in an additional 0 and overrides the cell below

Shiro00000 opened this issue · comments

I suspect this Bug came with the fix from #296 - "Replace parseFloat with parseLocaleNumber, so ReactGrid will respect locale-based separators."

When one copys from excel to notePad, one sees an empty line was pasted below the copyed number. This empty line is parsed in the reactGrid to 0, where it then overrides the cell below the cell, which was pasted in, with this 0. This is a huge problem.

An empty string should not be parsed to Number.

"Number()
The Number() function accepts a string parameter and converts it to an integer or floating point number, or returns NaN (Not a Number) if the input value doesn't represent a number. An interesting thing to note is that zero (0) is returned for an empty string (Number(''))."

found this on https://jasonwatmore.com/post/2021/10/15/vanilla-js-7-ways-to-convert-a-string-to-a-number-in-javascript#:~:text=The%20unary%20plus%20operator%20(%20%2B%20),string%20(%20%2B''%20).

and the pasted number is converted with "Number(trimmedNumberString);"
so an empty string will result in a 0 being pasted into the cell.

@Shiro00000 Thank you for bringing this to our attention. I've pushed a fix that ensures an empty string won't result in a 0 being pasted into the cell.

commented

@webloopbox
Your PR does fix that the number is not written as 0 anymore but the effected additional cell is still cleaned:

Before your fix the behavior was:
image
to
image
So only the cell with "5" was copied from Excel but two cells in the grid has been affected. So "6" was changed to "5" and "7" was changed to "0".
Now with your fix, the first cell will change from "6" to "5" but the second cell will be cleared from "7" to "NaN"
image

But the main issue is still present. Pasting from Excel results in clearing the last cell.

I think the issues itself is the content of the clipboard:
image
Excel adds an additional line at the end of the clipboard by default.

Is it possible to change the behavior that way NaN is handled as "do not change the current content"?

Is it possible to change the behavior that way NaN is handled as "do not change the current content"?

The ability to customize how pasted data behaves will be available in V5.