Using paste options when pasting from Clipboard

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

    • Post Options:
    • Link

    Posted 8 September 2017, 10: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

  • Posted 8 September 2017, 10: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

  • Posted 8 September 2017, 10:09 am EST

    Thanks for the help, that was the solution I was looking for!

  • Posted 8 September 2017, 10: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

  • Posted 23 August 2020, 1:45 pm EST

    [quote][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

    [/quote]

    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

  • Posted 24 August 2020, 7:00 am 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

  • Posted 15 September 2020, 10: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.

  • Posted 16 September 2020, 4:19 am 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

  • Posted 21 August 2024, 1:43 am EST

    Can anyone help me just to past values from excel rather values + formatting?

  • Posted 21 August 2024, 12:18 pm EST

    @lalit.sharma: It would be easier to answer if we knew what you were trying currently.

    In general, if you are hooking into the ClipboardPasting event, you can access args.pasteData.text to get the values without formatting. It looks like this in Angular:

    workbook.sheets.map(sheet => sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, (event, args) => {
    	const rawText = args.pasteData.text; // this is a string that looks like "val1\tval2\r\nval3\val4"
    }));

    Once you get that, you can parse the string, splitting on \t and \r\n and then push the value to your sheet.

  • Posted 22 August 2024, 1:45 am EST

    Hi Lalit,

    It appears that you’ve submitted the same query in the private ticket portal under case ID CAS-51893-R7F8J0. We have already provided a response there, so I recommend checking that for more details. If you encounter any further issues or need additional assistance, please don’t hesitate to reach out.

    Best regards,

Need extra support?

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

Learn More

Forum Channels