INDIRECT Function

SpreadJS provides an INDIRECT function similar to Microsoft Excel.

INDIRECT returns the reference specified by a text string. References are immediately evaluated to display their contents. Use INDIRECT when you want to change the reference to a cell within a formula without changing the formula itself. INDIRECT supports a1-style reference, r1c1-style reference, named reference, or a reference to a cell as a text string. For invalid cell references, INDIRECT returns the #REF! error value.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet> </gc-worksheet> <gc-worksheet> </gc-worksheet> </gc-spread-sheets> <div class="options-container"> <div class="option-row"> <label class="colorLabel">Enter a custom name below and set what it references. Then click the "Add custom name" button to add it to Spread for use in the cells.</label> </div> <div class="option-row"> <label class="sizedLabel">Custom name:</label> <input type="text" value="name1" id="customName" /> </div> <div class="option-row"> <label class="sizedLabel">Reference to:</label> <input type="text" value="$A$1" id="customReference" /> </div> <div class="option-row"> <input type="button" id="btnAddCustomName" value="Add custom name" title="Add a custom name for sample" @click="addIndirectCustomName($event)" /> </div> </div> </div> </template> <script setup> import '@mescius/spread-sheets-vue'; import { ref } from "vue"; import GC from "@mescius/spread-sheets"; const spreadRef = ref(null); let initSpread = function (spread) { spreadRef.value = spread; spread.suspendPaint(); let 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); let 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 (let i = 0, len = sampleData.length; i < len; i++) { let data = sampleData[i], row = 6 + i; sheet.setArray(row, 0, [data]); sheet.setFormula(row, 2, data[0]); } spread.resumePaint(); } let addIndirectCustomName = function (e) { let name = document.getElementById("customName").value, ref = document.getElementById("customReference").value, row = 15; if (name) { try { let sheet = spreadRef.value.sheets[0]; sheet.addCustomName(name, ref, 0, 0); sheet.setArray(row, 0, [[`=INDIRECT(${name})`, `${name} 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 + ')'); } catch (e) { alert("invalid custom name"); } } } </script> <style scoped> #app { height: 100%; } .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 { 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; } </style>
<!DOCTYPE html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>SpreadJS VUE</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> var System = SystemJS; System.import("./src/app.js"); System.import('$DEMOROOT$/en/lib/vue3/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', "systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js", '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-en': 'npm:@mescius/spread-sheets-resources-en/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js' }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);