Spread.Sheets Documentation
Using Code to Copy and Paste
Spread.Sheets Documentation > Sample Code > Sample Code Using the Clipboard > Using Code to Copy and Paste

You can copy and paste with code.

Using Code

This example implements copy and paste with code.

JavaScript
Copy Code

window.onload = function(){
                      var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
                      var sheet = spread.getActiveSheet();
sheet.setValue(0, 0, 1, GC.Spread.Sheets.SheetArea.viewport);
sheet.setValue(1, 0, 2, GC.Spread.Sheets.SheetArea.viewport);
sheet.setFormula(2, 0, "=A1+A2", GC.Spread.Sheets.SheetArea.viewport);
sheet.setValue(0, 1, 3, GC.Spread.Sheets.SheetArea.viewport);
sheet.setValue(1, 1, 4, GC.Spread.Sheets.SheetArea.viewport);
sheet.setFormula(2, 1, "=B1+B2", GC.Spread.Sheets.SheetArea.viewport);
var fromRange = [new GC.Spread.Sheets.Range(0, 0, 3, 2)];
var toRanges = [new GC.Spread.Sheets.Range(5, 0, 3, 2)];

$("#button1").click(function () {
    //Cut Paste Action
    spread.commandManager().execute({cmd: "clipboardPaste", sheetName: "Sheet1", fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: true, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all});
});
$("#button2").click(function () {
    spread.commandManager().execute({cmd: "clipboardPaste", sheetName: "Sheet1", fromSheet: sheet, fromRanges: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "", pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all});
});

See Also

Developer's Guide