사용자 정의 작업

SpreadJS는 사용자 정의 명령에 대한 실행 취소/다시 실행 작업을 완전히 지원합니다.

사용자가 실행 취소/다시 실행 명령을 유지하고자 하는 경우, 트랜잭션이 시작될 때 다음 코드 도중 사용자 정의 명령 변경 내용이 저장됩니다. 트랜잭션이 끝날 때 다음 코드 도중 사용자 정의 명령 변경 내용이 저장되었습니다. 트랜잭션을 다시 실행하려면 다음 코드 도중 명령 변경 내용이 실행 취소됩니다.
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss'), { sheetCount: 1 }); var undoManager = spread.undoManager(); _getElementById('undo').addEventListener('click', function() { undoManager.undo(); }); _getElementById('redo').addEventListener('click', function() { undoManager.redo(); }); _getElementById('setBackColor').addEventListener('click', function() { initSpread(spread); }); }; function initSpread(spread) { var sheet = spread.getActiveSheet(); var command = { canUndo: true, execute: function(spread, options, isUndo) { var Commands = GC.Spread.Sheets.Commands; if (isUndo) { Commands.undoTransaction(spread, options); return true; } else { Commands.startTransaction(spread, options); spread.suspendPaint(); var selections = options.selections; var value = options.backColor; selections.forEach(function(sel) { sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount).backColor(value); }); spread.resumePaint(); Commands.endTransaction(spread, options); return true; } } }; var selections = sheet.getSelections(); var commandManager = spread.commandManager(); commandManager.register('changeBackColor', command); commandManager.execute({ cmd: 'changeBackColor', sheetName: spread.getSheet(0).name(), selections: selections, backColor: 'rgb(130, 188, 0)' }); } function _getElementById(id) { return document.getElementById(id); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ko-kr"/> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <label >Please select a range and click 'Set BackColor' button will set backColor for the range, and click 'Undo' button and 'Redo' button will undo and redo the set backColor action.</label> <div class="option-row"> <input type="button" id="setBackColor" value="Set BackColor" /> </div> <div class="option-row"> <input type="button" id="undo" value="Undo" /> </div> <div class="option-row"> <input type="button" id="redo" value="Redo" /> </div> <hr> <div class="option-row"> <label >Use the keyboard shortcuts 'Ctrl-Z' to undo the custom action, and use the keyBoard shortcuts 'Ctrl-Y' to redo the custom action.</label> </div> </div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; } label { display: block; margin-bottom: 6px; } input[type=button] { margin-top: 6px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }