SpreadJS add the function SJS.TABLE to get the What-If Analysis Data Table results.
The SJS.TABLE function simulates inputting the value from inputs into input_cell , and then retrieves the value from result reference as the SJS.TABLE function result.
Argument
Description
result_reference
The cell location to retrieve the value. When all inputs are rows, it can be a range of 1 row and multiple columns. vice versa.
inputs
The values to input into input_cell. It can be a reference, an array, or a value.
input_cell
The cell to input the value. Must be a cell reference.
SJS.TABLE can completely cover traditional Data Table
Scenario
Traditional Data Table
Use SJS.TABLE
one-variable data table
Create DataTable A2:C10with column cell reference A2
B3: =SJS.TABLE(B2:C2,A3:A10,A2)
one-variable data table
Create DataTable A2:H5with row cell reference A2
B3: =SJS.TABLE(A3:A5,B2:H2,A2)
two-variable data table
Create DataTable A2:H5 with column cellreference A1 and row cell reference B1
B3: =SJS.TABLE(A2,B2:H2,B1,A3:A5,A1)
The What-If Analysis Data Table from Excel file will be transformed to SJS.TABLE function formula when importing.
When exporting to Excel, it attempts to convert to an Excel data table; if this fails, the formulas will be preserved.
SJS.TABLE is flexible
SJS.TABLE can use the various input
SJS.TABLE can use as the function parameter
<template>
<div class="sample-tutorial">
<div class="spreadsheet-container">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread">
<gc-worksheet>
</gc-worksheet>
</gc-spread-sheets>
<div ref="statusBar" class="status-bar"></div>
</div>
<div class="options-container">
<div class="option-row">
<label>Import / Export:</label>
<input type="file" ref="fileInput" accept=".ssjson,.sjs,.json,.xlsx" style="display:none" @change="handleFileChange" />
<input type="button" value="Import File" @click="handleImport" />
<label for="exportFormat" style="margin-top: 8px;">Export Format:</label>
<select id="exportFormat" v-model="exportFormat">
<option value="ssjson">SSJSON</option>
<option value="sjs">SJS</option>
<option value="xlsx">Excel (XLSX)</option>
</select>
<input type="button" value="Export File" @click="handleExport" />
</div>
<div class="option-row">
<label>Calculation Mode:</label>
<div class="radio-group">
<label class="radio-label">
<input type="radio" name="calcMode" value="0" v-model="calcMode" @change="handleCalcModeChange" /> Automatic
</label>
<label class="radio-label">
<input type="radio" name="calcMode" value="2" v-model="calcMode" @change="handleCalcModeChange" /> Partial
</label>
<label class="radio-label">
<input type="radio" name="calcMode" value="1" v-model="calcMode" @change="handleCalcModeChange" /> Manual
</label>
</div>
<input type="button" value="Calculate Now" @click="handleCalculateNow" />
</div>
<div class="option-row">
<label>Result:</label>
<div class="result-container">
<div :class="resultClass">{{result}}</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import '@mescius/spread-sheets-vue';
import '@mescius/spread-sheets-io';
import '@mescius/spread-sheets-calc-worker';
import GC from "@mescius/spread-sheets";
import { ref } from 'vue';
function isSJSFile(file) {
const fileName = file.name.toLowerCase();
return fileName.endsWith('.sjs');
}
let mySpread;
let result = ref('');
let resultClass = ref('');
let calcMode = ref('0');
let exportFormat = ref('ssjson');
const fileInput = ref(null);
const statusBar = ref(null);
let initSpread = function (spread) {
mySpread = spread;
// Add status bar
setTimeout(() => {
if (statusBar.value) {
const sb = new GC.Spread.Sheets.StatusBar.StatusBar(statusBar.value);
sb.bind(mySpread);
}
});
// Load data from datatable.js
mySpread.fromJSON(window.datatable);
}
let handleImport = function() {
fileInput.value.click();
}
let handleFileChange = function(e) {
const file = e.target.files[0];
if (!file) return;
const options = {
openMode: 2, // incremental loading
fullRecalc: true,
dynamicReferences: false,
incrementalCalculation: true
};
try {
if (isSJSFile(file)) {
mySpread.open(file, () => {
result.value = 'File imported successfully!';
resultClass.value = 'success';
setTimeout(() => {
result.value = '';
resultClass.value = '';
}, 2000);
}, (error) => {
result.value = 'Error importing file: ' + (error.errorMessage || error.message);
resultClass.value = 'error';
}, options);
} else {
mySpread.import(file, () => {
result.value = 'File imported successfully!';
resultClass.value = 'success';
setTimeout(() => {
result.value = '';
resultClass.value = '';
}, 2000);
}, (error) => {
result.value = 'Error importing file: ' + (error.errorMessage || error.message);
resultClass.value = 'error';
}, options);
}
} catch (error) {
result.value = 'Error importing file: ' + error.message;
resultClass.value = 'error';
}
e.target.value = '';
}
let handleExport = function() {
try {
const fileName = "export." + exportFormat.value;
if (exportFormat.value === "sjs") {
mySpread.save((blob) => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
a.click();
URL.revokeObjectURL(url);
result.value = 'File exported successfully!';
resultClass.value = 'success';
setTimeout(() => {
result.value = '';
resultClass.value = '';
}, 2000);
}, (error) => {
result.value = 'Error exporting file: ' + (error.errorMessage || error.message);
resultClass.value = 'error';
});
} else {
const options = { fileType: exportFormat.value === "ssjson" ? GC.Spread.Sheets.FileType.ssjson : GC.Spread.Sheets.FileType.excel };
mySpread.export((blob) => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
a.click();
URL.revokeObjectURL(url);
result.value = 'File exported successfully!';
resultClass.value = 'success';
setTimeout(() => {
result.value = '';
resultClass.value = '';
}, 2000);
}, (error) => {
result.value = 'Error exporting file: ' + (error.errorMessage || error.message);
resultClass.value = 'error';
}, options);
}
} catch (error) {
result.value = 'Error exporting file: ' + error.message;
resultClass.value = 'error';
}
}
let handleCalcModeChange = function() {
const mode = parseInt(calcMode.value);
mySpread.options.calculationMode = mode;
if (mode === 0) {
mySpread.calculate();
result.value = 'Calculation mode changed to: Automatic';
resultClass.value = 'success';
} else if (mode === 2) { // partial - calc formulas except for data table
mySpread.suspendCalcService();
mySpread.resumeCalcService();
result.value = 'Calculation mode changed to: Partial';
resultClass.value = 'success';
} else if (mode === 1) {
result.value = 'Calculation mode changed to: Manual';
resultClass.value = 'success';
}
setTimeout(() => {
result.value = '';
resultClass.value = '';
}, 2000);
}
let handleCalculateNow = function() {
try {
mySpread.calculate();
result.value = 'Calculation completed!';
resultClass.value = 'success';
setTimeout(() => {
result.value = '';
resultClass.value = '';
}, 2000);
} catch (error) {
result.value = 'Error calculating: ' + error.message;
resultClass.value = 'error';
}
}
</script>
<style scoped>
#app {
height: 100%;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.spreadsheet-container {
width: calc(100% - 280px);
height: 100%;
float: left;
display: flex;
flex-direction: column;
}
.sample-spreadsheets {
flex: 1;
overflow: hidden;
}
.status-bar {
height: 30px;
border-top: 1px solid #ccc;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
margin-bottom: 12px;
}
.option-row label {
display: block;
margin-bottom: 4px;
font-weight: bold;
font-size: 12px;
}
.description {
font-size: 12px;
color: #555;
line-height: 1.4;
margin: 0 0 8px 0;
}
.description-small {
font-size: 11px;
color: #666;
line-height: 1.3;
margin: 0 0 6px 0;
}
select {
width: 100%;
padding: 6px;
margin-bottom: 6px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
font-size: 12px;
}
input[type=button] {
width: 100%;
padding: 8px 6px;
margin-bottom: 6px;
background: #007acc;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
font-weight: bold;
}
input[type=button]:hover {
background: #005a9e;
}
input[type=button].secondary-button {
background: #6c757d;
}
input[type=button].secondary-button:hover {
background: #545b62;
}
.result-container {
padding: 8px;
border-radius: 3px;
min-height: 40px;
}
.success {
background: #d4edda;
color: #155724;
padding: 8px;
border-radius: 3px;
}
.error {
background: #f8d7da;
color: #721c24;
padding: 8px;
border-radius: 3px;
}
.radio-group {
margin-bottom: 8px;
}
.radio-label {
display: block;
font-weight: normal;
font-size: 12px;
margin-bottom: 4px;
cursor: pointer;
}
.radio-label input[type="radio"] {
margin-right: 6px;
cursor: pointer;
}
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="$DEMOROOT$/spread/source/data/datatable.js" type="text/javascript"></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/',
'cdn:': 'https://cdn.mescius.io/demoapps/packages/spreadjs/19.1.2-master-2026-06-10-2131/'
},
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': 'cdn:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-io': 'cdn:@mescius/spread-sheets-io/index.js',
'@mescius/spread-sheets-calc-worker': 'cdn:@mescius/spread-sheets-calc-worker/index.js',
'@mescius/spread-sheets-vue': 'cdn:@mescius/spread-sheets-vue/index.js'
},
meta: {
'*.css': { loader: 'systemjs-plugin-css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);