셀 바인딩 원본을 만든 다음 setBindingPath 메서드를 사용하여 지정된 시트 영역의 지정된 셀에서 셀 수준 바인딩의 바인딩 경로를 설정할 수 있습니다. 그런 다음 시트의 데이터 원본을 설정합니다. 예::
getBindingPath를 사용하여 지정된 시트 영역의 지정된 셀에서 셀 수준 바인딩의 바인딩 경로를 가져올 수 있습니다.
var person, sheet;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
initSpread(spread);
};
function initSpread(spread) {
var spreadNS = GC.Spread.Sheets;
sheet = spread.sheets[0];
sheet.suspendPaint();
sheet.setColumnWidth(0, 120);
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(2, 120);
sheet.setValue(0, 0, 'cell-binding');
sheet.setValue(2, 1, 'Name');
sheet.setValue(3, 1, 'Age');
sheet.setValue(4, 1, 'Sex');
sheet.setValue(5, 1, 'Address.postcode');
person = { name: "Wang Feng", age: 25, sex: "Male", address: { postcode: "710075" } };
document.getElementById("personName").value=person.name || "";
document.getElementById("personAge").value=person.age || "";
document.getElementById("personSex").value=person.sex || "";
document.getElementById("personPostcode").value=person.address.postcode || "";
var source = new spreadNS.Bindings.CellBindingSource(person);
sheet.setBindingPath(2, 2, "name");
sheet.setBindingPath(3, 2, "age");
sheet.setBindingPath(4, 2, "sex");
sheet.setBindingPath(5, 2, "address.postcode");
sheet.setDataSource(source);
sheet.setSelection(2, 2, 1, 1);
var path = sheet.getBindingPath(2, 2);
sheet.getRange(2, 2, 4, 1).backColor("rgb(208,206,206)");
document.getElementById("bindingPath").innerHTML=path || "";
sheet.bind(spreadNS.Events.SelectionChanged, function() {
var activeCell = sheet.getSelections()[0];
var path = sheet.getBindingPath(activeCell.row, activeCell.col);
document.getElementById("bindingPath").innerHTML=path || "";
});
sheet.bind(spreadNS.Events.CellChanged, function() {
document.getElementById("personName").value=person.name || "";
document.getElementById("personAge").value=person.age || "";
document.getElementById("personSex").value=person.sex || "";
document.getElementById("personPostcode").value=person.address.postcode || "";
});
sheet.resumePaint();
};
// These functions change the Person object that Spread is bound to
var updateName = function(value) {
if (person && sheet) {
person.name = value;
sheet.repaint();
}
};
var updateAge = function(value) {
if (person && sheet) {
person.age = value;
sheet.repaint();
}
};
var updateSex = function(value) {
if (person && sheet) {
person.sex = value;
sheet.repaint();
}
};
var updatePostcode = function(value) {
if (person && sheet) {
person.address.postcode = value;
sheet.repaint();
}
};
<!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">
<div class="option-row">
<label style="background-color:#F4F8EB;">Select one of the gray cells to get its binding. You can also change the Person object below to see it change in the Spread instance: change any of the text in the text boxes below.</label>
</div>
<div class="option-row">
<label>Name: </label>
<input type="text" id="personName" onkeyup="updateName(this.value)"/>
<label>Age: </label>
<input type="text" id="personAge" onkeyup="updateAge(this.value)"/>
<label>Sex: </label>
<input type="text" id="personSex" onkeyup="updateSex(this.value)"/>
<label>Postcode: </label>
<input type="text" id="personPostcode" onkeyup="updatePostcode(this.value)"/>
<label>GetBindingPath: </label>
<label id="bindingPath" style="color:darkgreen"></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;
margin-top: 10px;
}
label {
display: block;
margin-bottom: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
}
input[type=text] {
margin-top: 6px;
margin-bottom: 6px;
display: block;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}