您好,请参考以下代码来实现:
- let test = {
- canUndo: true,
- name: "test",
- execute: function (context, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- if (isUndo) {
- Commands.undoTransaction(context, options);
- return true;
- } else {
- Commands.startTransaction(context, options);
- let sheet = context.getSheetFromName(options.sheetName);
- console.log(sheet.name());
- Commands.endTransaction(context, options);
- return true;
- }
- },
- };
- spread.commandManager().register("test", test);
- let oldOpenMenu = spread.contextMenu.onOpenMenu;
- spread.contextMenu.onOpenMenu = function (
- menuData,
- itemsDataForShown,
- hitInfo,
- spread
- ) {
- oldOpenMenu.apply(this, arguments);
- let test = {
- command: "test",
- disable: false,
- name: "test",
- needKeepFocus: true,
- text: "测试...",
- };
- // 主要判断逻辑
- let row = hitInfo.worksheetHitInfo.row;
- let col = hitInfo.worksheetHitInfo.col;
- if (row > 3 && col > 3) {
- itemsDataForShown.push(test);
- }
- };
复制代码 |