我需要自己判断,某些单元格是否可以剪切,并在剪切后执行一些操作。
所以。我重写了Command.cut.execute方法,但是这样导致,剪切后,只复制到了第一个单元格的数据。
示例代码如下:
- const fun = function (sheet, sel, callback) {
- // 判断是否可以剪切
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const style = sheet.getStyle(iRow, iCol);
- if (style.locked) {
- toastr.error('不可剪切');
- return;
- }
- }
- }
- callback();
- }
-
- const cut = spreadNS.Commands.cut.execute;
- spreadNS.Commands.cut.execute = function (context, options, isUndo) {
- const self = this, sheet = context.getActiveSheet();
- const sels = sheet.getSelections();
- const sel = sels ? sels[0] : null;
- if (sel) {
- return fun(sheet, sel, function () {
- spreadNS.Commands.copy.execute(context, options, isUndo);
- });
- }
- }
复制代码
如果把callback前的代码注释掉,就可以正常剪切到全部数据
但是有这些代码,就只能剪切到选中的第一个单元格的数据
PS:我实际判断剪切的代码不是这样的,这只是为了在callback前添加一些判断代码而已。
|