How to set tag and undo tag by keyPress

Posted by: khoapcse90038 on 29 March 2023, 1:02 pm EST

  • Posted 29 March 2023, 1:02 pm EST - Updated 29 March 2023, 1:08 pm EST

    Hi teams,

    I input content “KhoaPC” in cell A7 and set tag: “khoapc tag”.

    When i delete content by keyPress Delete. This content was removed, but tag in cell couldn’t.

    Can you help me how to remove tag and content when delete cell & undo when use Ctrl + Z (or undo).


  • Posted 30 March 2023, 3:46 pm EST


    When you press Delete key, the “clearValues” command is executed in SpreadJS. This command only removes the values from the selected cell range. It does not remove tags, styles etc.

    You can create a custom command which removes values as well as tags from the selected cell range. You can utilize cellRange.clear() method to remove tags from a cell range. You need to remove default command “clearValues” from Delete key binding and register custom command with command manager using commandManager.register() method. So that, when you press Delete key, the custom command is executed.

    Please refer to the code snippet and attached sample for further understanding.

        let commandManager = spread.commandManager();
        // creates a command
        let command = {
            canUndo: true,
            execute: function (context, options, isUndo) {
                let Commands = GC.Spread.Sheets.Commands;
                options.cmd = "customDelete";
                if (isUndo) {
                    Commands.undoTransaction(context, options);
                    return true;
                } else {
                    Commands.startTransaction(context, options);
                    let sheet = context.getActiveSheet();
                    let selections = sheet.getSelections();
                    for (let selection of selections) {
                        let range = sheet.getRange(selection.row, selection.col, selection.rowCount, selection.colCount);
                    Commands.endTransaction(context, options);
                    return true;
        // removes the default clearValues command
        commandManager.register("clearValues", null, GC.Spread.Commands.Key.del, false, false, false, false);
        // adds a custom command to delete values and tags in the selected cell range
        commandManager.register("customDelete", command, GC.Spread.Commands.Key.del, false, false, false, false);


    Please let us know if you face any issues. You could created the SpreadJS Cases on the dedicated SpreadJS Forum at

    Doc references:



    StorageType enumeration:



Need extra support?

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

Learn More

Forum Channels