您好,
示例代码如下,完整代码请参考附件demo:- // 创建命令
- var newMenuItem = {
- canUndo: true,
- name: "newMenuItem",
- execute: function (context, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- if (isUndo) {
- Commands.undoTransaction(context, options);
- return true;
- } else {
- Commands.startTransaction(context, options);
- var sheet = context.getSheetFromName(options.sheetName);
- alert("添加的新右键菜单项");
- Commands.endTransaction(context, options);
- return true;
- }
- }
- };
- // 注册命令
- spread.commandManager().register("newMenuItem", newMenuItem);
- function MyContextMenu() { }
- MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(spread);
- MyContextMenu.prototype.onOpenMenu = function (menuData, itemsDataForShown, hitInfo, spread) {
- var sheetIndex = spread.getActiveSheetIndex()
- // 如果为sheet1,则添加新项
- if (sheetIndex == 0) {
- itemsDataForShown.push({
- text: "新项",
- name: "newItem",
- command: "newMenuItem",
- workArea: "viewportcolHeaderrowHeaderslicercorner"
- });
- }
- };
- var contextMenu = new MyContextMenu();
- spread.contextMenu = contextMenu;
复制代码
|
|