数据对象单元格类型

数据对象单元格类型为使用自定义数据提供了一种更方便的方式,其类型为对象。

一个数据对象单元格类型接受1个参数format,一个格式字符串,包含PROPERTY函数或点运算符。 它决定如何显示单元格的值,其类型是作为字符串的对象。 这是该类的定义。 这是示例代码。
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); var sheet = spread.getActiveSheet(); sheet.setColumnWidth(1, 500); //set a DataObject celltype which uses WEBSERVICE function to provide data sheet.setFormula(1, 1, '=FILTERJSON(WEBSERVICE("https://demodata.grapecity.com/northwind/api/v1/Products/1"))'); var cellType1 = new GC.Spread.Sheets.CellTypes.DataObject('=@.productName & " " & @.unitPrice'); sheet.setCellType(1, 1, cellType1); var baseApiUrl = getBaseApiUrl(); var dataManager = spread.dataManager(); var productTable = dataManager.addTable("productTable", { remote: { read: { url: baseApiUrl + "/Product" } } }); productTable.primaryKey("id"); var supplierTable = dataManager.addTable("supplierTable", { remote: { read: { url: baseApiUrl + "/Supplier" } } }); dataManager.addRelationship(productTable, "SupplierId", "supplier", supplierTable, "Id", "products"); Promise.all([productTable.fetch(), supplierTable.fetch()]).then(function () { spread.suspendPaint(); //set a DataObject celltype which use QUERY function to provide data sheet.setFormula(2, 1, '=QUERY("productTable?Id=1",,true)'); var cellType2 = new GC.Spread.Sheets.CellTypes.DataObject('=IFERROR(@.ProductName & " " & @.UnitPrice, "")'); sheet.setCellType(2, 1, cellType2); spread.resumePaint(); }); spread.resumePaint(); } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/SpreadJSTutorial\//)[0] + 'server/api'; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="spreadjs culture" content="zh-cn" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/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$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.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; margin: 0; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; }