Handle clipboardOptions on paste

Posted by: razeris563 on 9 November 2021, 8:29 pm EST

    • Post Options:
    • Link

    Posted 9 November 2021, 8:29 pm EST

    Hey guys, i’m having problem with setting paste options. Basically what I want to achieve is to paste everything from the clipboard on ctrl+v if the content was copied from my spreadJS canvas, but copy only values if it was copied from for example google sheets, excel etc.

    My current code looks something like:

    spread.bind(GC.Spread.Sheets.Events.ClipboardPasting,  (_, { sheet, pasteData }) => {
    // this if just an example for checking if what's in clipboard comes from GS
        if (pasteData.html.includes('<google-sheets-html-origin>')) {
          sheet.options.clipBoardOptions = 1;
        } else {
          sheet.options.clipBoardOptions = 0;
        }
      });
    

    The problem with this solution is that it changes after the pasting. For example I copy from google sheets, then I paste into spreadJS and it didn’t change but if i paste it once more, it works. It seems as if these options are being set too late but there isn’t any “beforeClipboardPaste” event or something. Thank you for the help!

  • Posted 10 November 2021, 10:51 pm EST

    Him,

    For this, You may override the clipboatrd paste command. Please refer to the following code snippet and let me know if you face any issues.

    
      let old = GC.Spread.Sheets.Commands.clipboardPaste.execute;
    
      GC.Spread.Sheets.Commands.clipboardPaste.execute = function (
        spread,
        options,
        isUndo
      ) {
        if (options.clipboardHtml.includes("<google-sheets-html-origin>")) {
          options.pasteOption = 1;
        } else {
          options.pasteOption = 0;
        }
        old.apply(this, arguments);
      };
    }
    
    

    API References:

    ClipboardPaste command: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Commands.clipboardPaste.html

    Regards.

    Avinash

Need extra support?

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

Learn More

Forum Channels