本帖最后由 鸳鸯配2024 于 2024-8-5 16:12 编辑
- config.commandMap = {
- "insertMutiRows": {
- text: "上方添加行",
- commandName: "insertMutiRows",
- },
- "insertMutiRowsDown": {
- text: "下方添加行",
- commandName: "insertMutiRowsDown",
- },
-
- }
- }
- var insertRowsByCounts = {
- canUndo: true,
- canExcute: function () {
- console.log(arguments)
- },
- execute: function (spread, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- if (isUndo) {
- Commands.undoTransaction(spread, options);
- return true;
- } else {
- Commands.startTransaction(spread, options);
- if (options.commandOptions) {
- console.log('在上方插入' + options.commandOptions);
- var sheet = spread.getSheetFromName(options.sheetName);
- sheet.suspendPaint();
- sheet.addRows(options.activeRow, 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.commandOptions);
- var sheet = spread.getSheetFromName(options.sheetName);
- sheet.suspendPaint();
- sheet.addRows(options.activeRow, parseInt(options.commandOptions));
- sheet.resumePaint();
- }
- Commands.endTransaction(spread, options);
- return true;
- }
- }
- };
- var commandManager = spread.commandManager();
- let insertRowAndCopyContent = {
- canUndo: true,
- execute: function (context, options, isUndo) {
- let Commands = GC.Spread.Sheets.Commands;
- options.cmd = "insertRowAndCopyContent";
- if (isUndo) {
- Commands.undoTransaction(context, options);
- return true;
- } else {
- Commands.startTransaction(context, options);
- context.suspendPaint();
- context.suspendEvent();
- var sheet = context.getSheetFromName(options.sheetName);
- var selections = sheet.getSelections();
- for(var i = 0; i < selections.length; i++){
- var row = selections[i].row;
- sheet.addRows(row,options.rowCount);
- var fromRange = [new GC.Spread.Sheets.Range(row + options.rowCount, 0, 1, sheet.getColumnCount())];
- var toRanges = [new GC.Spread.Sheets.Range(row, 0, options.rowCount, sheet.getColumnCount())];
- spread.commandManager().execute({cmd: "clipboardPaste", sheetName: options.sheetName, fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.formulasAndFormatting});
- }
-
- context.resumeEvent();
- context.resumePaint();
- Commands.endTransaction(context, 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);
- // 获取旧的菜单
- 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") {
- var supMenuItemContainer = menuItemView[0];
- var inputBlock = createInput();
- // var btnupBlock = createBtn();
- supMenuItemContainer.appendChild(inputBlock);
- // supMenuItemContainer.appendChild(btnupBlock);
- }
- // console.log(menuItemData.name, '--menuItemData.name--666')
- if (menuItemData.name === "insertMutiRowsDown") {
- // console.log(menuItemView, '--menuItemView--')
- var supMenuItemContainer = menuItemView[0];
- 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("inputBlock")[0]
- return ele.value;
- }else if (menuItemData && menuItemData.name === "insertMutiRowsDown") {
- var ele = document.getElementsByClassName("inputBlock")[0]
- return ele.value;
- } else {
- return oldgetCommandOptions.apply(this, arguments)
- }
- };
复制代码
上方添加行 是生效的
下方添加行 这个是不生效的,不知道问题在哪,希望能帮忙看下。
|
|