How to copy formatted cells between two instances of SpreadJS

Posted by: james.henke on 4 October 2019, 4:54 am EST

  • Posted 4 October 2019, 4:54 am EST

    We need to allow our users to copy and paste formatted cells between two instances of SpreadJS.

    If we use the default keyboard handlers for ctrl-c, ctrl-x, and ctrl-v this works just fine.

    However, we have clipboard use polices that have to be enforced to limit when the clipboard can be used, so we are overriding the default keyboard handlers for those keys.

    We have handlers that copies the values from the sheet to the clipboard and then pastes them in the sheet, but it does not support any of the formatting.

    We know, buy looking on the clipboard, when the allowCopyPasteExcelStyle is used and using the default keyboard handlers, you put on the clipboard an XML flavor that has all the formatting.

    Is there an API call we can make to get that XML so we can put it on the clipboard?
    Or is there a way to call the default keyboard handlers from our keyboard handlers after we do our policy processing?

    Thanks
  • Replied 8 October 2019, 3:54 pm EST

    Hi James,

    If I understand correctly what you need to do is that before copy/pasting you need to perform some checks and decide it the user should be able to copy/paste. In this case, you may simply handle the ClipboardChanging/ClipboardPasting event and perform the required checks and cancel the event if required. Please refer to the following code snippet:
    spread.bind(GC.Spread.Sheets.Events.ClipboardChanging, function(e, args) {
    let shouldCancelCopy = false;
    // perform cehcks

    // cancel copy operation(if required)
    args.cancel = shouldCancelCopy;
    });

    You may also access the args.copyData property inside the handler to inspect the data being copied.
    Please let us know if you had a different requirement.

    Regards
    Sharad
  • Replied 22 October 2019, 3:15 am EST

    Thanks for getting back to me, I'll give this a try.
Need extra support?

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

Learn More

Forum Channels