セルレベルバインディング

セルにデータソースを連結できます。SpreadJSでは、セルレベルの連結がサポートされます。

<p>特定のシート領域の特定セルでセルレベルの連結を行うには、セル連結ソースを作成してから、<strong>setBindingPath</strong>メソッドを使用して、連結パスを設定します。次に、シートのデータソースを設定します。次に、例を示します。</p> <pre><code class="hljs js language-js"> <span class="hljs-keyword">var</span> person = { <span class="hljs-attr">name</span>: <span class="hljs-string">'Wang feng'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">25</span>, <span class="hljs-attr">sex</span>: <span class="hljs-string">'male'</span>, <span class="hljs-attr">address</span>: { <span class="hljs-attr">postcode</span>: <span class="hljs-string">'710075'</span> } }; <span class="hljs-keyword">var</span> source = <span class="hljs-keyword">new</span> GC.Spread.Sheets.Bindings.CellBindingSource(person); sheet.setBindingPath(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-string">'name'</span>); sheet.setBindingPath(<span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-string">'age'</span>); sheet.setBindingPath(<span class="hljs-number">4</span>, <span class="hljs-number">1</span>, <span class="hljs-string">'sex'</span>); sheet.setBindingPath(<span class="hljs-number">5</span>, <span class="hljs-number">1</span>, <span class="hljs-string">'address.postcode'</span>); sheet.setDataSource(source); </code></pre> <p>特定のシート領域の特定セルでセルレベルの連結が行われている場合、この連結パスを取得するには、<strong>getBindingPath</strong>メソッドを使用します。</p>
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var spreadNS = GC.Spread.Sheets; var 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'); var person = { name: "Wang feng", age: 25, sex: "male", address: { postcode: "710075" } }; 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.resumePaint(); };
<!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/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/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 style="background-color:lavender;">灰色のセルのいずれかを選択すると、このセルの連結パスを取得できます。</label> </div> <div class="option-row"> <label>GetBindingPath:&nbsp;&nbsp;</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; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }