How can i copy/paste between 2 workbook

Posted by: ngocnguyen09910060 on 8 May 2022, 9:44 pm EST

  • Posted 8 May 2022, 9:44 pm EST

    Hi teams,

    On my web application, i init SpreadJS with default options.
    On browser, i open my web application on 2 tabs.
    This is some cases when i copy/paste:
    1. On browser tab 1, click row header to select row 1, copy and paste to row 2 => OK
    2. On browser tab 1, click row header to select row 1 and copy. After that, change to browser tab 2, paste isn't working.
    How can i copy/paste between browser tab ?
    Please help me.
  • Replied 10 May 2022, 3:29 pm EST

    Hi Ngọc,

    I think you are using the context menu's copy/paste options. That's why the content is not being pasted in the different workbook. This is the technical limitation of being a web application. Copying the range using the context menu and copying the range using Ctrl + C both uses different clipboards.

    Performing copy with context menu uses the internal clipboard and by Ctrl + C/ Ctrl + V, it uses the global clipboard and the web applications don't have access to the global clipboard that's why the range is not being pasted.

    Also, note that Excel has access to the system clipboard that is why it may work in Excel. If you want to perform the copy/paste between the browser tabs, use Ctrl+C/Ctrl+V to perform copy/paste operations.

    I hope this clarifies your issue. Please let us know if you need further assistance on this query. We would be happy to help you.

    Regards
    Ankit
  • Replied 10 May 2022, 6:04 pm EST

    Hi ankit.kumar,
    I have tested 2 case for this issue.
    Case 1: Select range of cells in workbook 1, Ctrl+C and Ctrl+V to workbook 2 => It's working well.


    Case 2: click row header to select a row in workbook 1, Ctrl+C and Ctrl+V to workbook 2 => It's not working.


    You have explained to me that content is not being pasted in the different workbook because it uses different clipboards.
    So, please explain to me why case 1 is working well.

    Thank you.
  • Replied 10 May 2022, 6:27 pm EST

    Hi Ngọc,

    This might happen because by default the copyPasteHeaderOptions is set to allHeaders and therefore on pasting, it will paste the row number plus all the row content and that will exceed the number of rows in another workbook. You should set the extend paste option to true so that the paste range is enough for pasting.

    spread.options.allowExtendPasteRange = true;
    spread.options.copyPasteHeaderOptions = GC.Spread.Sheets.CopyPasteHeaderOptions.noHeaders;


    For example, you can refer to the following sample that I have created for you with the options: https://jscodemine.grapecity.com/share/H7_-tPhuj0mLTZT7c6QsAQ/

    Workbook Options: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.Sheets.Workbook~options.html

    Please try with the above sample and let us know if you need further assistance on this issue.

    Regards
    Ankit
  • Replied 10 May 2022, 8:35 pm EST

    Hi ankit.kumar,

    Awsome. It's working well. Thank you very much.

    I have another question: in selected row, i have a cell that is locked. When i paste, i want to paste all cell of row except locked row.
    How can i do it ?
  • Replied 15 May 2022, 7:55 pm EST

    HI,

    We are sorry but this is why the design we can not partially paste. If the cell range contains any locked cell the paste will be prevented Excel also does the same.

    Further, if you do want to achieve this functionality you may need to override the paste command to store the locked cells before pasting and set the value again after pasting the cells. 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) {
    /*unprotect the sheet so that the spread can paste on the locked cells*/
    spread.getActiveSheet().options.isProtected = false;
    /*save the cellRange Data here using options.pastedrange*/
    console.log(options.pastedRange);
    let value = old.apply(this, arguments);

    /*restore the saved text to the options pastedRange*/

    spread.getActiveSheet().options.isProtected = true;

    return value;
    };


    Regards,
    Avinash
Need extra support?

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

Learn More

Forum Channels