您好,请参考以下代码:
var command = {
canUndo: true,
execute: function (context, options, isUndo) {
options.cmd = "delete";
var Commands = GC.Spread.Sheets.Commands;
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
let sheet = context.getActiveSheet();
let selections = sheet.getSelections();
for (const selection of selections) {
let range = sheet.getRange(selection.row, selection.col, selection.rowCount, selection.colCount);
range.clear(GC.Spread.Sheets.StorageType.data);
}
Commands.endTransaction(context, options);
return true;
}
},
};
spread.commandManager().register("delete", command);
spread
.commandManager()
.setShortcutKey(
"delete",
GC.Spread.Commands.Key.backspace,
false,
false,
false,
false
); |