react-datasheet-grid icon indicating copy to clipboard operation
react-datasheet-grid copied to clipboard

Paste format when pasting from Excel file

Open lucasbozzo opened this issue 1 year ago • 5 comments

When pasting values from an Excel file, the Grid is using the HTML format, instead of Plain Text. This is troublesome as Excel can have many visual formats and the Grid is not using the raw value. Take as an example a value "12345.67" in Excel. Depending on the cell width, Excel will show the value trimmed, rounded or even replaced with "####". image

These are the values used if HTML format is first, which are not correct: image

However, Plain Text contains the correct raw values: image

Proposal: Change the evaluation to consider clipboard format text/plain first and text/html second.

Second proposal: Control the order of evaluation with a prop. Some prop called clipboardFormatPriority, with an array of values text/html,text/plain, text.

lucasbozzo avatar Nov 11 '24 11:11 lucasbozzo

@nick-keller I have created the PR #368 for your consideration 👍

lucasbozzo avatar Nov 14 '24 09:11 lucasbozzo

Thx for contributing @lucasbozzo The issue I have with this is that doing it the other way also has edge cases. Notably for managing whitespaces and line return that just don't work with plain text... Are there any other solution? If you can copy / paste it from Excel to another Excel file, there must be a way to get that data correctly.

nick-keller avatar Nov 27 '24 10:11 nick-keller

@nick-keller that is a fair question. Agree. I will have a deeper look at this. A very high level search lead me to Sheetjs. Their approach is to use all of the formats, which I think is interesting: https://docs.sheetjs.com/docs/demos/local/clipboard/#browser-reading-paste image

lucasbozzo avatar Dec 13 '24 14:12 lucasbozzo

I think at least somehow give an option where we can override which data type to parse if we know we don't want to use one or the other could be a good start. At least for the advance users.

tsuzumiC avatar Feb 14 '25 15:02 tsuzumiC

Please let us know if you plan to take any action on this issue. @nick-keller

EyR1oN avatar Feb 19 '25 15:02 EyR1oN