本帖最后由 Ellia.Duan 于 2024-1-11 11:49 编辑
您好,可以参考此代码:
- var sheet = spread.getSheet(0);
- sheet.addSpan(0, 0, 1, 5)
- sheet.addSpan(1, 0, 1, 5)
- sheet.setArray(2, 3, [['地址'], ['北京'], ['济南']])
- sheet.setArray(2, 4, [['名称'], ['张三'], ['李四']])
- sheet.getRange(2, 3, 3, 1).backColor("yellow");
- sheet.getRange(2, 4, 3, 1).backColor("pink");
- spread.suspendPaint()
- let rowCount = sheet.getUsedRange(GC.Spread.Sheets.UsedRangeType.all).rowCount;
- let colCount = sheet.getUsedRange(GC.Spread.Sheets.UsedRangeType.all).colCount;
- if (sheet.setColumnCount() <= colCount) {
- sheet.setColumnCount(colCount + 1)
- }
- var fromRange1 = [new GC.Spread.Sheets.Range(2, 3, rowCount, 1)];
- var toRanges1 = [new GC.Spread.Sheets.Range(2, colCount + 1, rowCount, 1)];
- spread.commandManager().execute({
- cmd: "clipboardPaste", sheetName:sheet.name(),
- fromSheet: sheet, fromRanges: fromRange1,
- pastedRanges: toRanges1, isCutting: false, clipboardText: "",
- pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all
- });
- let fromRange2 = [new GC.Spread.Sheets.Range(2, 4, rowCount, 1)];
- let toRanges2 = [new GC.Spread.Sheets.Range(2, 3, rowCount, 1)];
- spread.commandManager().execute({
- cmd: "clipboardPaste", sheetName:sheet.name(),
- fromSheet: sheet, fromRanges: fromRange2,
- pastedRanges: toRanges2, isCutting: false, clipboardText: "",
- pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all
- });
- let fromRange3 = [new GC.Spread.Sheets.Range(2, colCount + 1, rowCount, 1)];
- let toRanges3 = [new GC.Spread.Sheets.Range(2, 4, rowCount, 1)];
- spread.commandManager().execute({
- cmd: "clipboardPaste", sheetName:sheet.name(),
- fromSheet: sheet, fromRanges: fromRange3,
- pastedRanges: toRanges3, isCutting: true, clipboardText: "",
- pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all
- });
- spread.resumePaint()
复制代码 其中pasteOption可以修改枚举值,上述代码给出的值是all,您还可以设置
https://demo.grapecity.com.cn/sp ... ipboardpasteoptions
结果如下:
|