本帖最后由 qunma 于 2020-6-17 10:48 编辑
setDefaultStyle(){
const activeSheet = this.spread.getActiveSheet();
const defaultStyle = activeSheet.getDefaultStyle(GC.Spread.Sheets.SheetArea.viewport)
defaultStyle.font = 'italic 700 13.3333px Calibri'
activeSheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
}
this.registerCommand('setDefaultStyle',this.setDefaultStyle, [])
registerCommand(cmdName, operateFun, params) {
let that = this;
// 如果不存在该指令则注册
if (!this.spread.commandManager()[cmdName]) {
let _this = this;
this.spread.commandManager().register(cmdName,
{
canUndo: true,
execute: function (context, options, isUndo) {
var Commands = GC.Spread.Sheets.Commands;
// 在此加cmd名称
options.cmd = cmdName;
if (isUndo) {
// isUndo 为true时,调用undoTransaction
Commands.undoTransaction(context, options);
that.captureUndoCommand(options);//捕获撤销的指令 根据个别指令单独去处理数据逻辑
_this.undoRedoOperate();
_this.getUndoRedoStatus();//更新撤销和重做的状态
return true;
} else {
// 开始事务
Commands.startTransaction(context, options);
operateFun(...options.params)
// 结束事务
// spread恢复焦点
_this.spread.focus()
Commands.endTransaction(context, options);
that.captureEndCommand(options);//捕获重做的指令 根据个别指令单独去处理数据逻辑
_this.undoRedoOperate();
_this.getUndoRedoStatus();//更新撤销和重做的状态
return true;
}
}
});
}
let activeSheet = this.spread.getActiveSheet()
// 执行指令
this.spread.commandManager().execute({
cmd: cmdName,
params,
sheet: activeSheet,
ranges: activeSheet.getSelections(),
sheetName: activeSheet.name()
});
},
|