- config.commandMap = {
- fontFamily:fontFamilyCmd,
- "insertMuticols": {
- text: "左侧添加列",
- commandName: "insertMuticols",
- },
- "insertMutiRowsDown": {
- text: "下方添加行",
- commandName: "insertMutiRowsDown",
- },
复制代码
- let insertMuticolsLeft = {
- canUndo: true,
- canExcute: function () {
- console.log(arguments)
- },
- execute: function (spread, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- console.log(options, '--options--')
- if (isUndo) {
- Commands.undoTransaction(spread, options);
- return true;
- } else {
- Commands.startTransaction(spread, options);
- if (options.commandOptions) {
- console.log(options, '---在左侧插入列++++' + options.commandOptions);
- var sheet = spread.getSheetFromName(options.sheetName);
- sheet.suspendPaint();
- sheet.addColumn(options.activeCol + 1, parseInt(options.commandOptions));
- sheet.resumePaint();
- }
- Commands.endTransaction(spread, options);
- return true;
- }
- }
- };
- let insertRowsByCountsDown = {
- canUndo: true,
- canExcute: function () {
- console.log(arguments)
- },
- execute: function (spread, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- console.log(options, '--options--')
- if (isUndo) {
- Commands.undoTransaction(spread, options);
- return true;
- } else {
- Commands.startTransaction(spread, options);
- if (options.commandOptions) {
- console.log(options, '---在下方插入++++' + options.commandOptions);
- var sheet = spread.getSheetFromName(options.sheetName);
- sheet.suspendPaint();
- sheet.addRows(options.activeRow + 1, parseInt(options.commandOptions));
- sheet.resumePaint();
- }
- Commands.endTransaction(spread, options);
- return true;
- }
- }
- };
复制代码
- var commandManager = spread.commandManager();
- commandManager.register("insertRowAndCopyContent", insertRowAndCopyContent);
- commandManager.register("insertMutiRows", insertRowsByCounts, null, false, false, false, false);
- commandManager.register("insertMutiRowsDown", insertRowsByCountsDown, null, false, false, false, false);
- commandManager.register("insertMuticols", insertMuticolsLeft, null, false, false, false, false);
- //
- // 获取旧的菜单
- var oldCreateMenuItemElement = spread.contextMenu.menuView.createMenuItemElement;
- spread.contextMenu.menuView.createMenuItemElement = function (menuItemData) {
- var self = this;
- var menuItemView = oldCreateMenuItemElement.call(self, menuItemData);
- if (menuItemData.name === "insertMutiRows" || menuItemData.name === "insertMutiRowsDown" || menuItemData.name === "insertMuticols") {
- var supMenuItemContainer = menuItemView[0];
- var inputBlock = createInput(menuItemData.name);
- // var inputBlock = createInput();
- // var btnupBlock = createBtn();
- supMenuItemContainer.appendChild(inputBlock);
- // supMenuItemContainer.appendChild(btnupBlock);
- }
- return menuItemView;
- }
- var oldgetCommandOptions = spread.contextMenu.menuView.getCommandOptions;
- spread.contextMenu.menuView.getCommandOptions = function (menuItemData, host, event) {
- console.log(menuItemData.name, '--menuItemData.name--')
- if (menuItemData && menuItemData.name === "insertMutiRows") {
- var ele = document.getElementsByClassName("inputBlockinsertMutiRows")[0]
- return ele.value;
- } else if (menuItemData && menuItemData.name === "insertMuticols") {
- var ele = document.getElementsByClassName("inputBlockinsertMuticols")[0]
- return ele.value;
- }else if (menuItemData && menuItemData.name === "insertMutiRowsDown") {
- var ele = document.getElementsByClassName("inputBlockinsertMutiRowsDown")[0]
- return ele.value;
- } else {
- return oldgetCommandOptions.apply(this, arguments)
- }
- };
复制代码
- function createInput(className) {
- var inputBlock = document.createElement('input');
- inputBlock.type = 'text';
- inputBlock.value = '1';
- inputBlock.className = 'inputBlock' + className;
- // inputBlock.className = 'inputBlock';
- inputBlock.style = 'width: 20px;';
- inputBlock.setAttribute('gcUIElement', 'gcContextMenu');
- inputBlock.onclick = function (ev) {
- if (ev.target) {
- ev.stopPropagation()
- }
- }
- return inputBlock;
- }
复制代码
添加行是生效的,但是新增列是不生效的。 insertMuticolsLeft 这是新增列的方法
|
|