您好,我这边做了一个命令的Demo,可以在编辑的时候同时给另一个sheet中的单元格添加tag,撤回时可以同时撤回输入和tag的设置,请参考:
let myEditCell = Object.assign({}, GC.Spread.Sheets.Commands.editCell);
myEditCell.canUndo = false;
spread.commandManager().register("myEditCell", myEditCell);
let test = {
canUndo: true,
name: "test",
execute: function (context, options, isUndo) {
options.sheetName = [
spread.getSheet(0).name(),
spread.getSheet(1).name(),
];
let Commands = GC.Spread.Sheets.Commands;
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
let sheetName = options.sheetName[0];
let { row, col, newValue, autoFormat } = options;
spread.commandManager().execute({
cmd: "myEditCell",
sheetName,
row,
col,
newValue,
autoFormat,
});
let sheet2 = context.getSheet(1);
sheet2.setTag(row, col, "tag:" + newValue);
Commands.endTransaction(context, options);
return true;
}
},
};
spread.commandManager().register("editCell", test);
document.querySelector("#button1").addEventListener("click", function () {
spread.commandManager().execute({
cmd: "editCell",
sheetName: ["Sheet1", "Sheet2"],
row: 1,
col: 2,
newValue: "red",
autoFormat: true,
});
});
是的,sheet.autoFitRow(row)是一个特殊的API,会生成撤销重做栈中的步骤。 |