Skip to content
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

Carriage return inserted inside string when pasting from Excel, but not from text #5647

Closed
rvictordelta opened this issue Dec 7, 2018 · 7 comments

Comments

Projects
None yet
6 participants
@rvictordelta
Copy link

commented Dec 7, 2018

Description

When pasting a long string that contains a space from Excel into Handontable, a carriage return character is inserted next to the space. This does not happen when pasting text from other sources.

I could not find a pattern for the length of the string, but it seems to occur if the string is longer.

It appears this was not an issue in 6.0.1, but is an issue in 6.2.0

Steps to reproduce

  1. Input string with length greater than ~22 and containing a space into an Excel cell
  2. Copy the cell from Excel into a handsontable
  3. Note that a carriage return is inserted next to the space

Demo

http://jsfiddle.net/gbL6mj4v/

Your environment

  • Handsontable version: 6.2.0
  • Browser Name and version: Chrome 70
  • Operating System: Windows 7
@AMBudnik

This comment has been minimized.

Copy link
Contributor

commented Dec 7, 2018

Thank you for sharing @rvictordelta

this issue should be fixed with #5477

@AMBudnik

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2018

It looks like it works the same in v 6.2.1 so #5477 did not fix it.

@rvictordelta do you get the same result?

Excel
image 1

Handsontable
image

@gregiare

This comment has been minimized.

Copy link

commented Dec 13, 2018

I also get the same results with 6.2.1 if I paste lines like this from Excel.

Bridge Drawing 1
Bridge Drawing 2
Bridge Drawing 3
Bridge Drawing 4
Bridge Drawing 1
Bridge Drawing 2
Bridge Drawing 3
Bridge Drawing 4
Bridge Drawing 1
Bridge Drawing 2

@AMBudnik

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2018

Thank you for feedback @gregiare

I thought that it might be related to what we had here #5477 but after fixing #5477 this issue still remains.

@andrewQwer

This comment has been minimized.

Copy link

commented Feb 7, 2019

This happens because when cell is copied its data looks like html content with table/td tags. Something like this:

<large html>
<table>
<td>Text copied
             from Excel</td>
<large html>

For some reason copied text has line breaks inside <td> even if there are no any line breaks in original text entered to the Excel cell. For html it is not considered as line break, but when CopyPaste plugin parses it using tableToArray(textHTML); there is a row inside tableToArray function: cell.innerHTML = cell.innerHTML.trim().replace(/<br(.|)>(\n?)/, '\n'); So as you may see all <br/> tags and \n occurrences are converted to \n
But when I add line breaks explicit copied text looks like this:

  <td attributes>Some
  text with<br>
    <span style='mso-spacerun:yes'> </span>line break</td>

Here we can see that <br/> is added when user places explicit line break. So I would skip\n from copied html at all.

@gregiare

This comment has been minimized.

Copy link

commented Feb 22, 2019

This is caused by the way Excel puts data into the html clipboard. It also has a problem when a column of data has repeating number sequences. In some cases it will replace the repeating values with #. I have fixed this in my copy of hansontable.full.js by commenting out the following block;

`var textHTML = event.clipboardData.getData('text/html');

if (textHTML && /(<table)|(<TABLE)/.test(textHTML)) {
pastedData = (0, _utils.tableToArray)(textHTML);
} else {
pastedData = event.clipboardData.getData('text/plain');
}`

And adding the following line;

pastedData = event.clipboardData.getData('text/plain');

This basically stops it from getting the pasted data from the html clipboard and gets it from the plain text clipboard instead. I have seen no issues with pasting from Excel after doing this. I can't say whether it will cause issues when pasting from other applications because the bulk of my users want to paste from Excel.

@AMBudnik

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

This issue has been solved with #5684 in v 7.1.0. Again, thank you for sharing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.