Data Table

The primary objective of the What-If Analysis Data Table is to display calculation results under different inputs.

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
import { Component, NgModule, enableProdMode, ViewChild, ElementRef } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { FormsModule } from '@angular/forms'; import { SpreadSheetsModule } from '@mescius/spread-sheets-angular'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-io'; import '@mescius/spread-sheets-calc-worker'; import './styles.css'; function isSJSFile(file: File): boolean { const fileName = file.name.toLowerCase(); return fileName.endsWith('.sjs'); } @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { @ViewChild('fileInput') fileInput!: ElementRef; @ViewChild('statusBar') statusBarElement!: ElementRef; spread: GC.Spread.Sheets.Workbook; result: string = ''; resultClass: string = ''; calcMode: string = '0'; exportFormat: string = 'ssjson'; hostStyle = { width: '100%', height: '100%' }; constructor() { } initSpread($event: any) { this.spread = $event.spread; // Add status bar setTimeout(() => { if (this.statusBarElement) { const statusBar = new GC.Spread.Sheets.StatusBar.StatusBar(this.statusBarElement.nativeElement); statusBar.bind(this.spread); } }); // Load data from datatable.js this.spread.fromJSON((window as any).datatable); } handleImport() { this.fileInput.nativeElement.click(); } handleFileChange($event: any) { const file = $event.target.files[0]; if (!file) return; const options = { openMode: 2, // incremental loading fullRecalc: true, dynamicReferences: false, incrementalCalculation: true }; try { if (isSJSFile(file)) { this.spread.open(file, () => { this.result = 'File imported successfully!'; this.resultClass = 'success'; setTimeout(() => { this.result = ''; this.resultClass = ''; }, 2000); }, (error: any) => { this.result = 'Error importing file: ' + (error.errorMessage || error.message); this.resultClass = 'error'; }, options); } else { this.spread.import(file, () => { this.result = 'File imported successfully!'; this.resultClass = 'success'; setTimeout(() => { this.result = ''; this.resultClass = ''; }, 2000); }, (error: any) => { this.result = 'Error importing file: ' + (error.errorMessage || error.message); this.resultClass = 'error'; }, options); } } catch (error: any) { this.result = 'Error importing file: ' + error.message; this.resultClass = 'error'; } $event.target.value = ''; } handleExport() { try { const fileName = "export." + this.exportFormat; if (this.exportFormat === "sjs") { this.spread.save((blob: Blob) => { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = fileName; a.click(); URL.revokeObjectURL(url); this.result = 'File exported successfully!'; this.resultClass = 'success'; setTimeout(() => { this.result = ''; this.resultClass = ''; }, 2000); }, (error: any) => { this.result = 'Error exporting file: ' + (error.errorMessage || error.message); this.resultClass = 'error'; }); } else { const options = { fileType: this.exportFormat === "ssjson" ? GC.Spread.Sheets.FileType.ssjson : GC.Spread.Sheets.FileType.excel }; this.spread.export((blob: Blob) => { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = fileName; a.click(); URL.revokeObjectURL(url); this.result = 'File exported successfully!'; this.resultClass = 'success'; setTimeout(() => { this.result = ''; this.resultClass = ''; }, 2000); }, (error: any) => { this.result = 'Error exporting file: ' + (error.errorMessage || error.message); this.resultClass = 'error'; }, options); } } catch (error: any) { this.result = 'Error exporting file: ' + error.message; this.resultClass = 'error'; } } handleCalcModeChange() { const mode = parseInt(this.calcMode); this.spread.options.calculationMode = mode; if (mode === 0) { this.spread.calculate(); this.result = 'Calculation mode changed to: Automatic'; this.resultClass = 'success'; } else if (mode === 2) { // partial - calc formulas except for data table this.spread.suspendCalcService(); this.spread.resumeCalcService(); this.result = 'Calculation mode changed to: Partial'; this.resultClass = 'success'; } else if (mode === 1) { this.result = 'Calculation mode changed to: Manual'; this.resultClass = 'success'; } setTimeout(() => { this.result = ''; this.resultClass = ''; }, 2000); } handleCalculateNow() { try { this.spread.calculate(); this.result = 'Calculation completed!'; this.resultClass = 'success'; setTimeout(() => { this.result = ''; this.resultClass = ''; }, 2000); } catch (error: any) { this.result = 'Error calculating: ' + error.message; this.resultClass = 'error'; } } } @NgModule({ imports: [BrowserModule, FormsModule, SpreadSheetsModule], declarations: [AppComponent], exports: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule);
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Polyfills --> <script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script> <script src="$DEMOROOT$/spread/source/data/datatable.js" type="text/javascript"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.import('@angular/compiler'); System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('$DEMOROOT$/en/lib/angular/license.ts'); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html>
<div class="sample-tutorial"> <div class="spreadsheet-container"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> <gc-worksheet> </gc-worksheet> </gc-spread-sheets> <div #statusBar class="status-bar"></div> </div> <div class="options-container"> <div class="option-row"> <label>Import / Export:</label> <input type="file" #fileInput accept=".ssjson,.sjs,.json,.xlsx" style="display:none" (change)="handleFileChange($event)" /> <input type="button" value="Import File" (click)="handleImport()" /> <label for="exportFormat" style="margin-top: 8px;">Export Format:</label> <select id="exportFormat" [(ngModel)]="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" [(ngModel)]="calcMode" (change)="handleCalcModeChange()" /> Automatic </label> <label class="radio-label"> <input type="radio" name="calcMode" value="2" [(ngModel)]="calcMode" (change)="handleCalcModeChange()" /> Partial </label> <label class="radio-label"> <input type="radio" name="calcMode" value="1" [(ngModel)]="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>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .spreadsheet-container { width: calc(100% - 280px); height: 100%; float: left; display: flex; flex-direction: column; } .spreadsheet-container > gc-spread-sheets { flex: 1; overflow: hidden; } .status-bar { height: 30px; border-top: 1px solid #ccc; } .options-container { float: right; width: 280px; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .option-row { margin-bottom: 12px; } .option-row label { display: block; margin-bottom: 4px; font-weight: bold; font-size: 12px; } input[type=text], input[type=number] { width: 100%; padding: 6px; border: 1px solid #ccc; border-radius: 3px; box-sizing: border-box; } 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; } .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; }
(function (global) { System.config({ transpiler: 'ts', typescriptOptions: { tsconfig: true }, meta: { 'typescript': { "exports": "ts" }, '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/', 'cdn:': 'https://cdn.mescius.io/demoapps/packages/spreadjs/19.1.0-master-2026-05-10-2130/' }, // map tells the System loader where to look for things map: { 'core-js': 'npm:core-js/client/shim.min.js', 'zone': 'npm:zone.js/fesm2015/zone.min.js', 'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js', '@angular/core': 'npm:@angular/core/fesm2022', '@angular/common': 'npm:@angular/common/fesm2022/common.mjs', '@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs', '@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs', '@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs', '@angular/router': 'npm:@angular/router/fesm2022/router.mjs', '@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs', 'jszip': 'npm:jszip/dist/jszip.min.js', 'typescript': 'npm:typescript/lib/typescript.js', 'ts': './plugin.js', 'tslib':'npm:tslib/tslib.js', 'css': 'npm:systemjs-plugin-css/css.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-angular': 'cdn:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'ts' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, "node_modules/@angular": { defaultExtension: 'mjs' }, "@mescius/spread-sheets-angular": { defaultExtension: 'mjs' }, '@angular/core': { defaultExtension: 'mjs', main: 'core.mjs' } } }); })(this);