Wrong decimal separator when pasting data copied from a handsontable

Tags: #<Tag:0x00007f344959b9b8>

Hi guys,

So, I don’t know if this is a known issue but I couldn’t really find a solution for this. If I have a Handsontable with a numeric cell set to use “,” as decimal separator, when I copy the data from this cell and paste it somewhere else, the data is pasted with “.” as decimal separator instead of “,”.

http://jsfiddle.net/handsoncode/xbj2g41z/

If you go to the fiddle above, select the data in the first row and last column (70,20 €) and paste it somewhere else, you will get “70.2”, instead of “70,20 €” or even “70,2”.

Is there a way to change this behavior so the copied data is pasted as it is displayed (70,20 €), or at very least, keep the correct decimal separator? (70,2)

I’m using:

Angular 12
“handsontable”: “9.0.1”,
@handsontable/angular": “9.0.1”,

Thank you very much in advance for the help!

Hi @talentos.risingstar

I got this working on Chrome 91 / Windows 10

reproduction

The last column is set to use a comma as a decimal separator but the column before it uses a dot.

Hi @aleksandra_budnik, sorry I was not very clear, the problem is when you paste the data somewhere else that is not the Handsontable (e.g. Excel, Word, Notepad, Email).

Handsontable to Handsontable works just fine for me as well, the problem is just when I try to use the data somewhere else.

The 70,20€ that we see is actually 70.2 in the data, and that is why 70.2 is the value you paste. And this is the same value you get in the beforeCopy hook http://jsfiddle.net/g3hf9sey/
To get the 70,20€ value, you’d need to do one of those

  1. Change the data to 70,20€
  2. Replace the value before/after it is copied

I did a “quick and dirty test” by replacing your function with this:

beforeCopy: function(){
arguments[0][0] = arguments[0][0].toString().replace('.',',');
	console.log(arguments)
},

And then the console output is correct, but when I paste the data I get some “strange” characters inserted into it, like this: “7 0 , 2”.

Do you know what could be causing it?

Edit: Looks like when I paste the values here, the strange characters are replaced with space, but if you try copy and pasting it yourself you will see what I mean!

Here’s an updated demo http://jsfiddle.net/7mcjdzwt/2/

Ps. for numeric column like Year, when the formatting is not defined, the default formatting takes place - the one with a dot.

Thanks @aleksandra_budnik, this solution worked for me! Have a nice day!

1 Like