It is possible to enable the use of the ‘Alt + ;’ keyboard shortcut in SpreadJS, which allows you to split a selected range like in Excel. This is helpful when you need to copy only the visible cells in a range that includes hidden rows or columns. The shortcut and it’s associated command, ‘selectVisibleCells’, are integrated into the Designer Component addon. If you do not use the Designer Component, you can instead add this shortcut in addition to several others by implementing the Keyboard Shortcuts extension.
If you need to split the cell range frequently in order to only copy the visible cells, it is possible to override the ‘copy’ command for the ‘Ctrl + C’ shortcut to automatically trigger this additional shortcut. This saves you from having to constantly input the ‘Alt + ;’ shortcut. However, bear in mind that overriding the ‘copy’ command will also affect the context menu’s “copy” function, since they both use the same command.
Here is an example of how you can override the “copy” command:
var copyExecuteFn = GC.Spread.Sheets.Commands.copy.execute;
GC.Spread.Sheets.Commands.copy.execute = function(context, options) {
context.commandManager().execute({cmd:"selectVisibleCells", sheetName: context.getActiveSheet().name()});
return copyExecuteFn(context, options);
};
We are simply executing the ‘selectVisibleCells’ action defined in the Designer Component/Keyboard Shortcuts extension any time the ‘copy’ command is executed, automatically splitting the range before ‘copy’ is fired via our copyExecuteFn variable.
Tye Glenz