本帖最后由 Dtttax 于 2023-2-24 14:06 编辑
如下代码,调用click方法。 做一个功能方法,传入一个方法,然后注册后不能ctrl+z撤回, 但是看执行又进入了undoTransaction。
click(){
this.undoExt(this.setCellValue,this.spread);
},
setCellValue(){
let spread=this.spread;
let sheet=spread.getActiveSheet();
let cell=sheet.getCell(10,2);
cell.value(100);
cell.backColor("red");
},
undoExt(fun,spread){
let commandManager = spread.commandManager();
let command = {
canUndo: true,
execute: function(spread, options, isUndo) {
let Commands = GC.Spread.Sheets.Commands;
if (isUndo) {
Commands.undoTransaction(spread, options);
return true;
} else {
Commands.startTransaction(spread, options);
fun.apply(this, arguments);
Commands.endTransaction(spread, options);
return true;
}
}
};
commandManager.register("undoExt", command);
commandManager.execute({
cmd: "undoExt",
spread:spread
});
},
|