SpreadJS Documentation > Sample Code > Sample Code Using the Clipboard > Using Code to Copy and Paste |
You can copy and paste with code.
This example implements copy and paste with code.
JavaScript |
Copy Code
|
---|---|
$(document).ready(function () { //There are two buttons in html page with the id "cutPasteBtn" and "copyPasteBtn". var spread = new GcSpread.Sheets.Spread($("#ss").get(0),{sheetCount:3}); var sheet = spread.getActiveSheet(); sheet.setValue(0, 0, 1, GcSpread.Sheets.SheetArea.viewport); sheet.setValue(1, 0, 2, GcSpread.Sheets.SheetArea.viewport); sheet.setFormula(2, 0, "=A1+A2", GcSpread.Sheets.SheetArea.viewport); sheet.setValue(0, 1, 3, GcSpread.Sheets.SheetArea.viewport); sheet.setValue(1, 1, 4, GcSpread.Sheets.SheetArea.viewport); sheet.setFormula(2, 1, "=B1+B2", GcSpread.Sheets.SheetArea.viewport); var fromRange = new GcSpread.Sheets.Range(0, 0, 3, 2); var toRanges = [new GcSpread.Sheets.Range(4, 0, 3, 2)]; $("#cutPasteBtn").click(function () { //Cut Paste Action var clipboardCutPasteAction = new GcSpread.Sheets.UndoRedo.ClipboardPasteUndoAction(sheet, sheet, sheet, { fromRange: fromRange, pastedRanges: toRanges, isCutting: true, clipboardText: "" }, GcSpread.Sheets.ClipboardPasteOptions.Values); clipboardCutPasteAction.execute(sheet); }); $("#copyPasteBtn").click(function () { //Copy Paste Action var clipboardCopyPasteAction = new GcSpread.Sheets.UndoRedo.ClipboardPasteUndoAction(sheet, sheet, sheet, { fromRange: fromRange, pastedRanges: toRanges, isCutting: false, clipboardText: "" }, GcSpread.Sheets.ClipboardPasteOptions.Values); clipboardCopyPasteAction.execute(sheet); }); }); |