Spreadおよびシートのイベントにバインドできます。イベントをバインドするにはbindメソッドを、イベントのバインドを解除するにはunbindメソッドを使用します。すべてのイベントをバインド解除するには、unbindAllメソッドを使用します。Spreadのbindおよびunbindは、jQueryのbindおよびunbindと同様に処理できます。次に、例を示します。
Spreadおよびシートにイベントをトリガさせたくない場合は、suspendEventを使用します。イベントのトリガを再開するには、resumeEventを使用します。次に、例を示します。
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(_getElementById("ss"), { sheetCount: 3 });
initSpread(spread);
};
function initSpread(spread) {
var spreadNS = GC.Spread.Sheets;
var sheet = spread.getActiveSheet();
spread.bind(spreadNS.Events.ActiveSheetChanged, function (e, args) {
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.ActiveSheetChanged + ' event called' + '\n' +
'oldSheetName: ' + args.oldSheet.name() + '\n' +
'newSheetName: ' + args.newSheet.name();
});
spread.bind(spreadNS.Events.CellClick, function (e, args) {
var sheetArea = args.sheetArea === 0 ? 'sheetCorner' : args.sheetArea === 1 ? 'columnHeader' : args.sheetArea === 2 ? 'rowHeader' : 'viewPort';
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.CellClick + ' event called' + '\n' +
'sheetArea: ' + sheetArea + '\n' +
'row: ' + args.row + '\n' +
'col: ' + args.col;
});
spread.bind(spreadNS.Events.SelectionChanging, function (e, args) {
var selection = args.newSelections.pop();
var sheetArea = args.sheetArea === 0 ? 'sheetCorner' : args.sheetArea === 1 ? 'columnHeader' : args.sheetArea === 2 ? 'rowHeader' : 'viewPort';
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.SelectionChanging + ' event called' + '\n' +
'sheetArea: ' + sheetArea + '\n' +
'row: ' + selection.row + '\n' +
'column: ' + selection.col + '\n' +
'rowCount: ' + selection.rowCount + '\n' +
'colCount: ' + selection.colCount;
});
spread.bind(spreadNS.Events.SelectionChanged, function (e, args) {
var selection = args.newSelections.pop();
if(selection.rowCount > 1 && selection.colCount > 1){
var sheetArea = args.sheetArea === 0 ? 'sheetCorner' : args.sheetArea === 1 ? 'columnHeader' : args.sheetArea === 2 ? 'rowHeader' : 'viewPort';
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.SelectionChanged + ' event called' + '\n' +
'sheetArea: ' + sheetArea + '\n' +
'row: ' + selection.row + '\n' +
'column: ' + selection.col + '\n' +
'rowCount: ' + selection.rowCount + '\n' +
'colCount: ' + selection.colCount;
}});
spread.bind(spreadNS.Events.EditStarting, function (e, args) {
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.EditStarting + ' event called' + '\n' +
'row: ' + args.row + '\n' +
'column: ' + args.col;
});
spread.bind(spreadNS.Events.EditEnded, function (e, args) {
_getElementById("showSpreadEvents").value=
'SpreadEvent: ' + GC.Spread.Sheets.Events.EditEnded + ' event called' + '\n' +
'row: ' + args.row + '\n' +
'column: ' + args.col + '\n' +
'text: ' + args.editingText;
});
};
function _getElementById(id){
return document.getElementById(id);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="ja-jp" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/data.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.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">
<div class="option-row">
<label>シートタブをクリックして、アクティブシートを変更してみましょう。セルをクリックするか、またはセル範囲を選択して、編集を開始してみましょう。</label>
</div>
<div class="option-row">
<textarea id="showSpreadEvents" cols="40" rows="8" style="width: 90%"></textarea>
</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;
margin-top: 10px;
}
label {
display: block;
margin-bottom: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}