Using paste options when pasting from Clipboard

Posted by: michaelrm on 8 September 2017, 1:09 am EST

  • Posted 8 September 2017, 1:09 am EST

    Is there any way to specify a Paste Option (All, Values, Formatting, Formulas) when pasting from the clipboard? Below are the methods I have tried to use and the reason why they didn't seem to work for this particular application:

    - GC.Spread.Sheets.Commands.copy - Successfully pasted fields contained in clipboard, but doesn't appear to provide any Paste Options.

    - GC.Spread.Sheets.Commands.clipboardPaste - Provides Paste Options but doesn't appear to provide the ability to set the clipboard as your copyFrom location.

    - instance.copyTo - Same issue as clipboardPaste method.

    I'm hoping that there may be a different method that would allow us to paste content with a specific Paste Option from the clipboard or perhaps something I'm missing in one of the methods listed above.

    Thanks,
    Michael
  • Replied 8 September 2017, 1:09 am EST

    Hi Michael,

    You can specify the options using the options.clipBoardOptions property on the sheet, as shown in the code snippet on this documentation page:

    http://sphelp.grapecity.com/webhelp/SpreadSheets10/webframe.html#clipboard.html

    Keep in mind that this will only affect pasting when the original data is copied from Spread and not outside sources. However, if you wanted to copy from Excel to Spread, you can use the options.allowCopyPasteExcelStyle property on the workbook, as shown in the documentation page here:

    http://sphelp.grapecity.com/webhelp/SpreadSheets10/webframe.html#JavascriptLibrary~GC.Spread.Sheets.Workbook~options.html

    Let me know if that helps.

    Regards,
    Kevin
  • Replied 8 September 2017, 1:09 am EST

    Thanks for the help, that was the solution I was looking for!
  • Marked as Answer

    Replied 8 September 2017, 1:09 am EST

    Hi Michael,

    I am happy to hear that! If you need any further assistance on this particular issue, feel free to reply back.

    Regards,
    Kevin
  • Replied 23 August 2020, 4:45 am EST

    [author]However, if you wanted to copy from Excel to Spread, you can use the options.allowCopyPasteExcelStyle property on the workbook, as shown in the documentation page here:

    http://sphelp.grapecity.com/webhelp/SpreadSheets10/webframe.html#JavascriptLibrary~GC.Spread.Sheets.Workbook~options.html[/spread_archive]


    Hi Kevin,

    I am having a challenge pasting values from an external Excel spreadsheet to SpreadJS workbook using the paste options on the context menu. It only works with the key combination (Ctrl + V).

    I noticed in the response above you mentioned that the 'allowCopyPasteExcelStyle' needs to be set to true but it still didn't work. How can I get the paste context menu option to work with external values?

    Your assistance will be highly appreciate.

    Regards,

    KG
  • Replied 23 August 2020, 10:00 pm EST

    Hi KG,

    SJS is not pasting data on context menu click because Due to the security reasons, Browsers, do not allow the web apps 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 SJS ContextMenu click. So this is a technical limitation.

    Regards

    Avinash
  • Replied 15 September 2020, 1:26 am EST

    @Avinash

    Your assertion that "Browsers, do not allow the web apps to access the clipboard until the user explicitly triggers the paste event by pressing ctrl + v or by using the system context menu" is at least partially untrue. There are modern APIs for doing clipboard operations programatically in web apps:

    https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard

    @kgaugelo.molema

    I haven't implemented a full solution but I have verified that it is possible to use the navigator.clipboard.readText() method to read data from the clipboard inside a method invoked by a context menu item. From there it should just be a matter of validating and parsing clipboard data before placing it into the spreadsheet.

    Also, I may be reading the documentation wrong, but I believe that allowCopyPasteExcelStyle attribute only affects copying and pasting styles (like colors and whatnot) from Excel. It doesn't somehow change copying and pasting of values to work more like Excel (or in other words Excel-style copy/paste). The method name is ambiguous, as the distinction between the two behaviors is easily lost, even to a native English speaker.
  • Replied 15 September 2020, 7:19 pm EST

    Hi Rick,

    Yes, you are right we could use the Clipboard API to access the clipboard.
    Regarding the allowCopyPasteExcelStyle option, yes when this option is enabled instead of copying just the values, cell styles like background color, font color, etc are copied to/from excel hence the name "ExcelStyle". It does not have any effect on the system clipboard copy/paste functionality.

    Regards
Need extra support?

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

Learn More

Forum Channels