TableSheet Reference in Worksheet Formulas

Worksheet formulas can cross-reference and summarize data in the TableSheet to create advanced report views.

Users can use structured references to reference the TableSheet in a Worksheet just like a table. The TableSheet name is the table name and the column caption is the table column. Here is the sample: It also supports the A1/R1C1 reference style, but it's not easy to read. The reference style can be used in cell formulas, charts, and conditional formats.
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 }); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; spread.options.allowDynamicArray = true; //init a data manager var baseApiUrl = getBaseApiUrl(); var dataManager = spread.dataManager(); //add product table var productTable = dataManager.addTable("productTable", { remote: { read: { url: baseApiUrl + "/Product" } } }); //add category table var categoryTable = dataManager.addTable("categoryTable", { remote: { read: { url: baseApiUrl + "/Category" } } }); //add relation ship dataManager.addRelationship(productTable, "CategoryId", "category", categoryTable, "Id", "products"); //init a table sheet var sheet = spread.addSheetTab(0, "TableSheet1", GC.Spread.Sheets.SheetType.tableSheet); sheet.options.allowAddNew = false; //hide new row sheet.actionColumn.options({ visible: false }); //hide action column sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); //bind a view to the table sheet var myView = productTable.addView("myView", [ { value: "Id", caption: "ID" }, { value: "category.CategoryName", caption: "Category", width: 100 }, { value: "ProductName", caption: "Name", width: 400 }, { value: "UnitPrice", caption: "Unit Price", width: 100 }, { value: "UnitsInStock", caption: "Units In Stock", width: 100 }, { value: "UnitsOnOrder", caption: "Units On Order", width: 100 }, { value: "=SUM([@UnitsInStock], [@UnitsOnOrder])", caption: "Total Amount", width: 100 }, { value: "=[@UnitPrice] * SUM([@UnitsInStock], [@UnitsOnOrder])", caption: "Total Price", width: 100 } ]); myView.fetch().then(function() { spread.suspendPaint(); sheet.setDataView(myView); var sheet1 = spread.getSheet(0); sheet1.setColumnWidth(0, 100); sheet1.setColumnWidth(1, 150); sheet1.setColumnWidth(2, 100); sheet1.setColumnWidth(3, 150); sheet1.setColumnWidth(4, 150); sheet1.setColumnWidth(5, 150); sheet1.setValue(0, 0, "Product Count") sheet1.setFormula(0, 1, "=COUNTA(TableSheet1[ID])"); sheet1.setValue(1, 0, 'Total Price') sheet1.setFormula(1, 1, '=SUM(TableSheet1[Total Price])'); applyTableStyleForRange(sheet1, 5, 0, 9, 6); sheet1.setValue(4, 0, "Category Summary:") sheet1.setArray(5, 0, [ ["Category", "Product", "On Order Cost", "Highest Unit Price", "Highest Price Product", "Highest Price In Stock"] ]); sheet1.setFormula(6, 0, '=UNIQUE(TableSheet1[Category])'); sheet1.setFormula(6, 1, '=COUNTIF(TableSheet1[Category], A7#)'); sheet1.setFormula(6, 3, '=MAXIFS(TableSheet1[Unit Price], TableSheet1[Category], A7#)'); for (var i = 7; i <= 14; i++) { sheet1.setFormula(i - 1, 2, '=SUMPRODUCT((TableSheet1[Category]=A' + i + ')*TableSheet1[Units On Order],TableSheet1[Unit Price])'); sheet1.setFormula(i - 1, 4, '=XLOOKUP(D' + i + ', IF(TableSheet1[Category] = A' + i + ', TableSheet1[Unit Price], -1), TableSheet1[Name])'); sheet1.setFormula(i - 1, 5, '=XLOOKUP(D' + i + ', IF(TableSheet1[Category] = A' + i + ', TableSheet1[Unit Price], -1), TableSheet1[Units In Stock])'); } sheet1.setValue(16, 0, "Out of Stock:") applyTableStyleForRange(sheet1, 17, 0, 6, 2); sheet1.setArray(17, 0, [ ["Category", "Product"] ]); sheet1.setFormula(18, 0, '=FILTER(TableSheet1[Category]:TableSheet1[Name], TableSheet1[Units In Stock] = 0)'); spread.setActiveSheetIndex(0); spread.resumePaint(); }); spread.resumePaint(); } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/demos\//)[0] + 'server/api'; } function applyTableStyleForRange(sheet, row, col, rowCount, colCount, options) { var tableName = "tmpTable"; var TableThemes = GC.Spread.Sheets.Tables.TableThemes; // use table to help set style then remove like convert table to range in Excel sheet.tables.add(tableName, row, col, rowCount, colCount, TableThemes.medium7, options); sheet.tables.remove(tableName, 2 /* keep style */ ); }
<!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/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Promise Polyfill for IE, https://www.npmjs.com/package/promise-polyfill --> <script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.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 id="optionContainer" class="optionContainer"> </div> </div> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; }