您好,
请参考附件demo,主要代码如下:
- //定义向下插入行且复制样式insertRowsBelow命令
- var insertRowsBelow = {
- canUndo: true,
- name: "insertRowsBelow",
- 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);
- sheet.suspendPaint();
- console.log(options.selections)
- var selection = options.selections[0];
- //向下插入行
- var row = selection.row;
- var rowCount = selection.rowCount;
- if (options.selections && options.selections.length) {
- sheet.addRows(row + 1, rowCount);
- }
- // 复制上一行样式:该示例仅针对单行插入,起参考作用。
- // 对于多行复制样式,请根据实际业务需求进行设计。
- sheet.copyTo(row, -1, row + 1, -1, 1, -1, GC.Spread.Sheets.CopyToOptions.style | GC.Spread.Sheets.CopyToOptions.span);
- sheet.resumePaint();
- Commands.endTransaction(context, options);
- return true;
- }
- }
- };
- // 注册命令
- spread.commandManager().register("insertRowsBelow", insertRowsBelow);
- // 替换原有插入命令
- function MyContextMenu() { }
- MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(spread);
- MyContextMenu.prototype.onOpenMenu = function (menuData, itemsDataForShown, hitInfo, spread) {
- itemsDataForShown.forEach(function (item, index) {
- if (item && item.name === "gc.spread.insertRows") {
- item.command = "insertRowsBelow"
- }
- });
- };
- var contextMenu = new MyContextMenu();
- spread.contextMenu = contextMenu;
复制代码
|
|