Copy/paste not working properly

Posted by: mserban on 21 February 2018, 8:07 pm EST

    • Post Options:
    • Link

    Posted 21 February 2018, 8:07 pm EST

    Hello,

    I understood that when the target range is smaller than the source range the paste behavior will fail and I can override this by setting the ‘allowExtendPasteRange’ to true.

    Now, the problem is that ‘isProtected’ property on the sheet is set to true, so that I can have both, locked and unlocked cells. When ‘isProtected’ is set to true, ‘allowExtendPasteRange’ seems to have an issue (although I only copy & paste a range of unlocked cells) and the behavior fails.

    If I set the ‘isProtected’ property to false, ‘allowExtendPasteRange’ works as it should but all the cells are unlocked.

    What can I do to have both locked and unlocked cells and to be able to paste and extend the target range accordingly?

    Thanks,

    Mircea

  • Posted 22 February 2018, 1:37 am EST

    +1

  • Posted 26 February 2018, 1:19 am EST

    Hi,

    Any news on this?

    Thanks.

  • Posted 27 February 2018, 1:55 am EST

    Ok, thank you.

  • Posted 27 February 2018, 4:34 am EST

    Hi,

    Let me get in touch with the development team regarding this behavior. It could be a design behavior when ‘isProtected’ is set to true, but I’ll get a confirmation on this and update you (Tracking Id - 254930)

  • Posted 6 March 2018, 3:58 am EST

    I have an update from the dev team regarding this behavior and this is a design behavior. When the sheet is protected, if the paste range contains locked cell, the paste behavior will fail.

    When allowExtendPasteRange set to true, it will extend the paste range to accept more data, but the new added row/cols(cells)'s locked is true by default. Hence, when sheet is protected, the extend paste behavior is handled as pasting on locked cells.

    To workaround the problem, you could set the default locked option to false on sheet.

    var style = sheet.getDefaultStyle();
    style.locked = false;
    sheet.setDefaultStyle(style);
    

    And try again

    Regards

  • Posted 7 March 2018, 1:08 am EST

    Hello,

    Thank you for your answer but it doesn’t seem to work that way either. I could try to unprotect sheet, paste and protect back but no event is triggered when I try to paste. Do you have any other ideas?

    Thanks,

    Mircea

  • Posted 7 March 2018, 11:34 pm EST

    Hi Mircea,

    The code provided earlier does not unprotect sheet. It sets the locked property of the default style of Spread to false, so that paste operation works as expected. However, it won’t work if the paste range contains locked cells, which is the design behavior of Spread.

  • Posted 8 March 2018, 12:46 am EST

    Hello,

    So, I have this piece of code, when initializing spread:

    
    spread.options.allowExtendPasteRange = true;
    var sheet = spread.getActiveSheet();
    var style = sheet.getDefaultStyle();
    style.locked = false;
    sheet.setDefaultStyle(style);
    
    

    Let’s say I have one range of 3 rows and 3 columns that I previously copied from Excel and I want to paste it on my spread sheet. In this very moment, I want to paste this range over the last row and I expect it to extend 2 more rows to add all the rows from clipboard. For this to happen, I have to set sheet.options.isProtected to false BUT none of the existing events gets active (ClipboardPasting, ClipboardChanging, ClipboardChanged, etc.). How do I get one event to trigger so I can change the isProtected property to false, paste the clipboard and change isProtected to true?

    I hope is all clear now.

    Thanks,

    Mircea

  • Posted 13 March 2018, 2:03 am EST

    Hello,

    You can get the document’s keydown event and set the isProtected property to false there.

    
    <script>
     function keyDownFunction(event)
            {          
                if (event.ctrlKey && event.keyCode == 90) {
      sheet.options.isProtected = false;            
                        }
                    }                              
        </script>
    <div id="ss" onkeydown="keyDownFunction(event)"></div>
    
    

    Thanks,

    Deepak Sharma

  • Posted 20 March 2018, 8:54 pm EST

    Hello,

    What about pasting from the context menu?

    Thanks,

    Mircea

  • Posted 21 March 2018, 12:57 am EST

    I just tried this and it doesn’t work, either

  • Posted 23 March 2018, 1:28 am EST

    Hello,

    As suggested earlier you would need to set the locked property of style to false while keeping the cells locked. Then set the style as default style for the sheet.

    
        var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
                var sheet = spread.getActiveSheet();
                sheet.setRowCount(4, GC.Spread.Sheets.SheetArea.viewport);
                sheet.setColumnCount(4, GC.Spread.Sheets.SheetArea.viewport);
             
                sheet.getRange(-1, 2,-1,1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
                sheet.getRange(1, 1, 2, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
    
                sheet.getCell(3, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
                sheet.options.isProtected = true;
                spread.options.allowExtendPasteRange = true;
    
                var style = sheet.getDefaultStyle();
                style.locked = false;
                sheet.setDefaultStyle(style);
    
    

    The last cell the pasted range should be unlocked in this case.

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels