INDIRECT関数

Spread.Sheetsは、Microsoft Excelと同様のINDIRECT関数を提供します。

<p>INDIRECT関数は、テキスト文字列によって指定した参照を返します。参照はただちに評価され、その内容が表示されます。<strong>INDIRECT</strong>は、数式自体を変更せずに、数式に含まれるセルへの参照を変更したい場合に使用します。</p> <p>INDIRECTは、A1参照形式、R1C1参照形式、名前付き参照、またはテキスト文字列としてのセル参照をサポートします。セル参照が無効な場合は、<strong>#REF!</strong>エラー値が返されます。</p>
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 }); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); var sheet = spread.sheets[0], sheet2 = spread.sheets[1]; sheet.setArray(0, 0, [["b1", 1], ["A", 2], ["B", 3]]); sheet2.setArray(0, 0, [["b3", 1], ["A", 3], ["B", 5]]); sheet.setValue(3, 0, "Random"); sheet.setFormula(3, 1, "=RANDBETWEEN(1,100)"); sheet.setValue(4, 0, "Now"); sheet.setFormula(4, 1, "=NOW()"); sheet.setArray(8, 0, [["Formula", "Description", "Result"]]); sheet.setColumnWidth(0, 165); sheet.setColumnWidth(1, 285); var sampleData = [ ['=INDIRECT("A1")', 'Value of A1 => "b1"'], ['=INDIRECT(A1)', 'Value of the reference of A1 => value of b1 => 1'], ['=INDIRECT("A"&(1+2))', 'Value of A3 => "B"'], ['=INDIRECT(A3&B2)', 'Value of B2 => 2'], ['=INDIRECT("Sheet2!"&A1)', 'Value of Sheet2\'s B1'], ['=INDIRECT("Sheet2!A1")', 'Value of Sheet2\'s A1'] ]; for (var i = 0, len = sampleData.length; i < len; i++) { var data = sampleData[i], row = 6 + i; sheet.setArray(row, 0, [data]); sheet.setFormula(row, 2, data[0]); } spread.resumePaint(); document.getElementById("btnAddCustomName").addEventListener('click',function () { var name = document.getElementById("customName").value, ref = document.getElementById("customReference").value, row = 15; if (name) { sheet.addCustomName(name, ref, 0, 0); sheet.setArray(row, 0, [['=INDIRECT(name1)', 'name1 is a custom name, if a valid cell reference is defined by it then use the value otherwise #REF!']]); sheet.setFormula(row, 2, '=INDIRECT(' + name + ')'); } }); }
<!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 class="colorLabel">以下の欄にカスタム名を入力し、その参照先を指定してください。[カスタム名を追加]ボタンをクリックすると、Spreadにこのカスタム名が追加され、セル内で使用できるようになります。</label> </div> <div class="option-row"> <label class="sizedLabel">カスタム名::</label> <input type="text" value="name1" id="customName" /> </div> <div class="option-row"> <label class="sizedLabel">参照先:</label> <input type="text" value="$A$1" id="customReference" /> </div> <div class="option-row"> <input type="button" id="btnAddCustomName" value="カスタム名を追加" title="カスタム名をサンプルに追加します" /> </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; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .option-row { margin-bottom: 12px; } input { width: 100%; padding: 4px 6px; margin-bottom: 6px; box-sizing: border-box; } input[type=button] { width: auto; } label { display: block; margin-bottom: 6px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }