了解了,要实现您的需求,需要重写四个command,示例代码如下:
- window.onload = function () {
- let spread = new GC.Spread.Sheets.Workbook(
- document.getElementById("gc-designer-container"),
- { sheetCount: 1 }
- );
- let command = {
- canUndo: false,
- execute: function (context, options, isUndo) {
- let Commands = GC.Spread.Sheets.Commands;
- if (isUndo) {
- Commands.undoTransaction(context, options);
- return true;
- } else {
- Commands.startTransaction(context, options);
- console.log("快捷键复制");
- let spread = context;
- let sheetName = options.sheetName;
- let command = {};
- command.cmd = "copy";
- command.sheetName = sheetName;
- command.callback = function () {
- options.callback(
- command.copyData.copyText,
- command.copyData.copyHtml
- );
- };
- spread.commandManager().execute(command);
- Commands.endTransaction(context, options);
- return true;
- }
- },
- };
- spread.commandManager().register("myCopy", command);
- spread
- .commandManager()
- .setShortcutKey(
- "myCopy",
- GC.Spread.Commands.Key.c,
- true,
- false,
- false,
- false
- );
- let commandV = {
- canUndo: false,
- execute: function (context, options, isUndo) {
- let Commands = GC.Spread.Sheets.Commands;
- if (isUndo) {
- Commands.undoTransaction(context, options);
- return true;
- } else {
- Commands.startTransaction(context, options);
- console.log("快捷键粘贴");
- let spread = context;
- let sheetName = options.sheetName;
- let command = {};
- command.cmd = "paste";
- command.sheetName = sheetName;
- spread.commandManager().execute(command);
- Commands.endTransaction(context, options);
- return true;
- }
- },
- };
- spread.commandManager().register("myPaste", commandV);
- spread
- .commandManager()
- .setShortcutKey(
- "myPaste",
- GC.Spread.Commands.Key.v,
- true,
- false,
- false,
- false
- );
- let contextcopycommand = GC.Spread.Sheets.Commands.copy;
- let oldCopyExecute = contextcopycommand.execute;
- contextcopycommand.execute = function (context, propertyName, args) {
- console.log("右键菜单复制");
- oldExecute.call(this, context, propertyName, args);
- };
- let contextpastecommand = GC.Spread.Sheets.Commands.paste;
- let oldPasteExecute = contextpastecommand.execute;
- contextpastecommand.execute = function (context, propertyName, args) {
- console.log("右键菜单粘贴");
- oldExecute.call(this, context, propertyName, args);
- };
- };
复制代码
|