重新根据您的需求谢了个Demo,在粘贴时候判断如果是在表格中粘贴,或者是在表格后面一行粘贴,就先调整表格大小,然后粘贴数据。
- spread.options.allowExtendPasteRange = true;
- var ResizeTableCommand = {
- canUndo: true,
- 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);
- if (options.rowCount && options.colCount) {
- sheet.tables.resize(options.table, options.rowCount, options.colCount);
- } else {
- sheet.tables.resize(options.table, options.range);
- }
- Commands.endTransaction(context, options);
- return true;
- }
- }
- };
- spread.commandManager().register("resizeTable", ResizeTableCommand, null, false, false, false,
- false);
- spread.bind(GC.Spread.Sheets.Events.ClipboardPasting, function (s, e) {
- var sheet = spread.getActiveSheet()
- var pastingRange = e.cellRange;
- var table = sheet.tables.find(pastingRange.row, pastingRange.col)
- if (table) {
- var tableRange = table.range();
- var newRowCount = (pastingRange.row + pastingRange.rowCount) - (tableRange.row +
- tableRange.rowCount);
- if (table.showFooter()) {
- newRowCount++;
- }
- if (newRowCount > 0) {
- spread.commandManager().execute({
- cmd: "resizeTable",
- sheetName: sheet.name(),
- table: table,
- rowCount: tableRange.rowCount + newRowCount,
- colCount: tableRange.colCount
- });
- // sheet.tables.resize(table, tableRange.rowCount + newRowCount, tableRange.colCount);
- }
- } else {
- table = sheet.tables.find(pastingRange.row - 1, pastingRange.col)
- if (table && !table.showFooter()) {
- var tableRange = table.range();
- // sheet.tables.resize(table, tableRange.rowCount + pastingRange.rowCount, tableRange.colCount);
- spread.commandManager().execute({
- cmd: "resizeTable",
- sheetName: sheet.name(),
- table: table,
- rowCount: tableRange.rowCount + pastingRange.rowCount,
- colCount: tableRange.colCount
- });
- }
- }
- })
- });
复制代码 |