Leverage OS clipboard for COPY/CUT from context menu

Posted by: davide.vago on 8 March 2021, 6:23 am EST

    • Post Options:
    • Link

    Posted 8 March 2021, 6:23 am EST

    Ctrl+c (copy) / Ctrl+x (cut) work both within a sheet and in a new sheet or new browser window, but those same options don’t work outside of a single sheet if selected from the right click menu.

    How to reproduce:

    Result:

    Works as expected

    • Right click on a cell and select copy

    • Move to the second tab and try to paste the copied value

    Result:

    Doesn’t work

  • Posted 9 March 2021, 1:29 am EST

    Hi Davide,

    The Observed behavior is expected. Due to security reasons, Browsers, do not allow the webapps to access the clipboard until the user explicitly triggers the paste event by pressing ctrl + v or by using the system context menu, hence Spread cannot read the clipboard data on the button(spread contextMenu ) click. That is why when we copy from the context menu it does change the global clipboard.

    regards

    Avinash

  • Posted 11 March 2021, 12:32 pm EST

    Hi Avinash,

    I don’t believe this is a reasonable explanation.

    As you can observe from this example: https://rawcdn.githack.com/sitepoint-editors/clipboardapi/a8dfad6a1355bbb79381e61a2ae68394af144cc2/demotext.html

    The Clipboard API permits you to read/write on your OS clipboard, which means the user could be able transfer data between tabs, the API is recent but it could easily cover the most used browsers as well as the common cases of (copy/pasting text)

    In the worst case scenario the Clipboard API is not available for a specific browser, the document.execCommand(‘copy’) should be good enough to permit the library accessing the OS clipboard and saving cell data.

    In order to copy advanced cell information (e.g. style, format, tag) the JSON methods stringify/parse can do the job.

    Regards,

    Davide

  • Posted 12 March 2021, 5:39 am EST

    Hi Davide,

    Yes, you are correct but the clipboard API is currently working as a draft by MDN that is why our devs have not added it to the context menu copy/paste feature.

    MDN Clipboard API: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API

    >>In order to copy advanced cell information (e.g. style, format, tag) the JSON methods stringify/parse can do the job.

    We could not do that because If we write the JSON string in the clipboard then it is going to stored as text and we paste it on excel then it will be pasted a simple text.

    Reagrds

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels