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

Pasting multi-line cells from Excel inserts a carriage return and spaces #6258

Closed
jonw-bb opened this issue Sep 11, 2019 · 8 comments
Closed

Pasting multi-line cells from Excel inserts a carriage return and spaces #6258

jonw-bb opened this issue Sep 11, 2019 · 8 comments

Comments

@jonw-bb
Copy link

@jonw-bb jonw-bb commented Sep 11, 2019

Description

Pasting a cell from Excel which contains multi-line text adds a carriage return after the first word of the first line. It also inserts extra spaces. While you can't see it in the screenshot below, if you edit the cell in handsontable, you will see spaces added to the beginning of each new line.

The pasted text in handsontable should retain the same formatting as Excel.

Text copied from Excel:
excel_multi_line

Pasted into Handsontable:
hot_multi_line

I believe this issue reported previously is exactly the same problem

I debugged the code in handsontable.full.js where it performs paste actions.

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

Here is an excerpt from the HTML from the clipboard after copying from Excel:

<table border=0 cellpadding=0 cellspacing=0 width=189 style='border-collapse:
 collapse;width:142pt'>
 <col width=189 style='mso-width-source:userset;mso-width-alt:6058;width:142pt'>
 <tr height=149 style='height:112.0pt'>
<!--StartFragment-->
  <td height=149 class=xl65 width=189 style='height:112.0pt;width:142pt'>Line
  1<br>
    Line 2<br>
    <br>
    Line 3<br>
    <br>
    Start of a paragrah<br>
    <br>
    Another paragraph</td>
<!--EndFragment-->
 </tr>
</table>

Notice how after the first "Line" word, there is a carriage return to the next line. This seems to reflect in the pasted text in handsontable. You seem to be using both a carriage return and the
tags.

Commenting some code as suggested here resolves the issue - #5647 (comment) But I assume the commented code is needed for other use cases.

Also please note this problem does not occur if copying from Google Sheets, since the HTML in the clipboard is a different format.

Steps to reproduce

  1. Open Microsoft Excel
  2. In an empty cell, type some text and have it so its multi-line (for new lines - Alt+Enter on Windows, Ctrl+Option+Enter on MacOs). Make sure the first line has more than one word.
  3. Come out of edit mode. Select the cell and copy it to clipboard
  4. In Handsontable, paste into a cell.

Demo

https://jsfiddle.net/handsoncode/8ffpsqt6/

Not possible to demo without using Excel. You can download a trial from Microsoft - https://products.office.com/en-gb/excel

Your environment

  • Handsontable version: 7.1.1
  • Browser Name and version: Chrome 76.0.3809.132
  • Operating System: MacOS High Sierra 10.13.6
  • Excel version: 16.28 (MacOS)
@jonw-bb

This comment has been minimized.

Copy link
Author

@jonw-bb jonw-bb commented Sep 11, 2019

I am aware of #5647 but it has not resolved this issue.

@jonw-bb jonw-bb changed the title Pasting multi-line cells from Excel inserts a carriage return Pasting multi-line cells from Excel inserts a carriage return and spaces Sep 11, 2019
@AMBudnik AMBudnik added the Type: Bug label Sep 12, 2019
@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented Sep 12, 2019

Thank you for sharing @jonw-bb I've replicated the issue.

@jonw-bb

This comment has been minimized.

Copy link
Author

@jonw-bb jonw-bb commented Sep 12, 2019

@AMBudnik thats good you can also replicate. Thanks.

It seems these issues are related to the ability to paste in text/html data type which I see was introduced here - #4931

Can you give me some examples of use cases where someone would want to paste as text/html? Because pasting as text/plain appears to solve most of my problems with pasting from Excel.

@wojciechczerniak

This comment has been minimized.

Copy link
Member

@wojciechczerniak wojciechczerniak commented Sep 13, 2019

Can you give me some examples of use cases where someone would want to paste as text/html? Because pasting as text/plain appears to solve most of my problems with pasting from Excel.

With text/plain you can paste only values. With text/html you get access to merged cells, number formatting, text formatting, formulas, cell styles and more.

@swistach swistach added this to the November 2019 milestone Nov 4, 2019
swistach added a commit that referenced this issue Nov 4, 2019
swistach added a commit that referenced this issue Nov 6, 2019
jansiegel added a commit that referenced this issue Nov 8, 2019
@aninde

This comment has been minimized.

Copy link

@aninde aninde commented Nov 15, 2019

@jonw-bb this issue will be fixed in 7.3.0. We plan to release it on next week.
I test it on your set of multi-line cell pasted from Excel 16.31 and it works.

Screenshot 2019-11-15 at 11 23 26

Screenshot 2019-11-15 at 11 27 00

Demo
v. 7.3.0 https://jsfiddle.net/aninde/4gn2q0ey/

@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented Nov 18, 2019

Works well on Windows Chrome 78 and FF 70

@aninde

This comment has been minimized.

Copy link

@aninde aninde commented Dec 9, 2019

The latest build of 7.3.0 v.(6.12) -is still fixed during testing on Chrome 78, Firefox 70, Safari 13, Microsoft Dev Edge / Mac OS Catalina and IE, Edge, Edge Dev / Windows 10. You can paste multi-line paragraphs from Excel, Numeric, Google Spreadsheet.
https://jsfiddle.net/aninde/nvohepzw/

@AMBudnik

This comment has been minimized.

Copy link
Contributor

@AMBudnik AMBudnik commented Dec 13, 2019

Hey @jonw-bb

we just released v 7.3.0 where we provide a fix for this issue. I hope that it will also solve the same issue in your project after updating.

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