nadbm / react-datasheet

Excel-like data grid (table) component for React
https://nadbm.github.io/react-datasheet/
MIT License
5.39k stars 457 forks source link

Bug: Copy and paste from MS Excel on a Windows machine pastes an extra empty cell #309

Open haihoang20 opened 2 years ago

haihoang20 commented 2 years ago

There's a bug that happens on Windows where copying and pasting multiple cells from MS Excel will paste an extra empty cell. This can unintentionally overwrite existing cells as seen in the screenshot. image image

This bug is reproducible on the demo as well https://nadbm.github.io/react-datasheet/

This does not happen on Mac.

christiankaindl commented 2 years ago

If anyone comes across this issue, it can be easily fixed by using the parsePaste prop on the component, and pass it a modified version of the default function with an added .trim() call:

<DataSheet
  parsePaste={(pastedString) => {
    return pastedString.trim().split(/\r\n|\n|\r/).map(row => row.split('\t'))
  }
/>

Fixed the issue for me

vanessa-sdt commented 3 months ago

Help please! How do I do this @christiankaindl