Data Object

DataObject 셀 유형은 유형이 개체인 사용자 정의 데이터를 사용하는 더욱 편리한 방법을 제공합니다.

데이터 개체 셀 유형은 PROPERTY 함수 또는 점 연산자를 포함하는 형식 문자열인 매개변수 1개 format을 수락합니다. 셀 값을 표시하는 방법과 어떤 유형이 문자열 개체인지 결정합니다. 다음은 클래스 정의입니다. 다음은 샘플 코드입니다.
/*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.mescius.io/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\/learn-spreadjs\//)[0] + 'server/api'; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="spreadjs culture" content="ko-kr" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/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$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.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; }