Paste into range with some protected cells

Posted by: a.gryn on 1 May 2023, 3:34 am EST

  • Posted 1 May 2023, 3:34 am EST


    I try to implement the following scenario: user selects some range and copies data to clipboard (or maybe clipboard contains data from another spreadsheet application)

    After that user selects some cell and triggers paste. The target range contains some non-modifiable/locked cells. I need to skip data in the source range that correspond to the locked cells in the target range and continue pasting from the next cell.

    Example: clipboard contains data of 4 cells. In the target range 1s cell is editable, next two cells are locked, 4th is editable.

    I want to paste data from the clipboard to the 1st cell, skip data of the 2nd and 3rd cell and paste 4th source cell data into 4th destination cell

    I can do it by manually iterating over clipboard data in ClipboardPasting event and changing cell values individually but your default processing also recognises data types (like numbers and dates) and pastes them correctly and I would like to preserve this.

    Thank you

  • Posted 2 May 2023, 11:39 pm EST


    Please note that paste operation can not be performed in locked cells in SpreadJS by default. This behavior is by design as it is in MS Excel. Since your use case is custom, it would require to implement custom logic to achieve the desired behavior.

    If you want to paste values in a cell range which includes locked cells and also ignore pasting values in locked cells then you would need to create a custom command and register the custom command with command manager using commandManager.register() method. You need to bind custom command with ctrl + v keys to execute that command.

    You can store the copy range when ClipboardChanging event is fired and implement your logic to inside the execute method of custom command to paste values in a cell range which contains locked cells accordingly.

    Please refer to the attached sample. The attached sample demonstrate basic implementation of how you can copy/paste values in cell range with locked cells. You may extend this as per your need.


    Please note that you can use editCell command to set values with recognized type.

    Doc reference


    ClipboardChanging event:

    editCell command:



Need extra support?

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

Learn More

Forum Channels