react-datasheet-grid
react-datasheet-grid copied to clipboard
Paste format when pasting from Excel file
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 "####".
These are the values used if HTML format is first, which are not correct:
However, Plain Text contains the correct raw values:
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.
@nick-keller I have created the PR #368 for your consideration 👍
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 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
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.
Please let us know if you plan to take any action on this issue. @nick-keller