好的,您参考下面的代码:
let command = {
canUndo: true,
execute: function (context, options, isUndo) {
let Commands = GC.Spread.Sheets.Commands;
options.cmd = "myClearValues";
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
let selections = spread.getActiveSheet().getSelections()[0];
console.log("command execute");
for (let i = selections.row; i < selections.rowCount; i++) {
for (let j = selections.col; j < selections.colCount; j++) {
if (sheet.getFormula(i, j) == null) {
continue;
} else {
console.log("contain formula");
return true;
}
}
}
spread.commandManager().execute({
cmd: "clearValues",
sheetName: "Sheet1",
ranges: [spread.getActiveSheet().getSelections()[0]],
});
Commands.endTransaction(context, options);
return true;
}
},
};
let commandManager = spread.commandManager();
commandManager.register("myClearValues", command);
spread
.commandManager()
.setShortcutKey(
"myClearValues",
45,
false,
false,
false,
false
);
代码的效果为按下Insert键触发自定义Command,实现Clear的效果。 |