Skip to content

copy-paste of numbers in numeric cells pastes a different number than the copied one. #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sturez opened this issue Feb 20, 2025 · 5 comments

Comments

@Sturez
Copy link

Sturez commented Feb 20, 2025

Describe the bug
When I copy-paste a number such as 990.06 from a notepad to a numeric cell, the number is very different. If I copy-paste from the grid itself, it works. I've tested also using the current development branch (column 0 - 3). Tested with version 4.1.13 and the problem is not there, it must be something specific of version 4.1.14.

Current behavior
When we paste 990.06 we get -30 912 713 608 000,00 

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots or gifs

Image

Your environment details

  • Device: desktop
  • OS: Windows
  • Browser: chrome, edge
@MateuszTrN
Copy link

MateuszTrN commented Mar 19, 2025

I'm almost sure it's something with parseLocaleNumber function but I didn't quite nailed it. funny thing is that I have the very same issue when I'm pasting with ctrl+v, but context menu paste works fine. I am suspicious of locale parsing as I copied values from an excel that came from a customer from new Zealand, cause when I created an excel it works fine. but pasting to notepad or via context menu works as expected. Just ctrl + v behaves like OP described. also! as you can see in the video - my issue only occurs when a number is less than 1000
https://github.com/user-attachments/assets/c7d43ed2-7cba-451e-9639-cc6631a7c83d

424348395-c7d43ed2-7cba-451e-9639-cc6631a7c83d.mov

@Morozov-it
Copy link

Morozov-it commented Apr 9, 2025

@Sturez I confirm this bug too. Only works up to v 4.1.13. I have same behavior and hope the develops of this lib will fix this bug!

@MateuszTrN
Copy link

MateuszTrN commented Apr 14, 2025

ok, I have some new discovering regarding this. My suspicion is that if a pasted number can be interpreted as a Date - it will be somehow transformed to date number. I've created a small proof of this.
this app has two inputs that if you copy one 4.31 - the paste will fail and will set some ridiculous number in the cell value, cause for some reason it will be interpreted as "31st of April" (which is already incorrect, and will return May 1st, but it is parsable)
however anything that could not be interpreted as a Date it will work fine - so 4.32 could not be treated as date because no month has 32 days - so it will be interpreted as a number (as expected).

@webloopbox sorry if I'm mistaken but I'm guessing you're a maintainer of this repo? is there any doc/md how do you set up development env? so I could run it locally and debug some more maybe even do a fix? I'm pretty in hurry with this one

https://stackblitz.com/edit/vitejs-vite-mckpxusj?file=src%2FApp.tsx

EDIT: I think I found the issue:

.map((line: string) => line.split("\t").map((t) => {
const parsedDate = parseExcelDate(t);
return parsedDate ? { type: "date", text: t, value: parsedDate.getTime() } : { type: "text", text: t, value: parseLocaleNumber(t) };
}));

I'm not sure how to approach it though - to be honest the only thing that would cover probably most of use cases (but wouldn't be 100% bulletproof) - is to check if the pasted string has at least two "." - then try to parse it as excel date, if it's only one - prioritize parsing as a number.

@webloopbox
Copy link
Contributor

@MateuszTrN I will try to deal with this issue as quickly as possible. If you need to run version 4 of reactgrid locally, you should switch to the develop branch. Starting it is pretty simple, there are no extra steps needed.

@MateuszTrN
Copy link

@MateuszTrN I will try to deal with this issue as quickly as possible. If you need to run version 4 of reactgrid locally, you should switch to the develop branch. Starting it is pretty simple, there are no extra steps needed.

yup,i figure the running part out, I just wasnt expecting it was THAT easy 🤣 anyway, I've set up a PR, it is A solution, but i'm not 100% it is THE solution. thanks for quick reply. let me know if i coule help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants