사용자는 구조화된 참조를 사용하여 워크시트에서 표와 같은 테이블 시트를 참조할 수 있습니다.
테이블 시트 이름은 표 이름이고 열 캡션은 표 열입니다. 샘플 코드는 다음과 같습니다.
또한 A1/R1C1 참조 스타일을 지원하지만 읽는 것이 어렵습니다.
참조 스타일은 셀 수식, 차트, 조건부 서식에서 사용할 수 있습니다.
사용자는 QUERY 함수를 사용하여 DataManager 표에서 데이터를 가져올 수 있습니다.
QUERY 구문
반환 유형
예시
전체 표
QUERY("table1")
전체 열
QUERY("table1", "column1")
데이터
QUERY("table1#1", "column1")QUERY("customer/abc@gmail.com", "name")
특정 행
QUERY("table1#1")QUERY("customer/abc@gmail.com")
행 필터
사용자는 간단한 행 필터를 사용할 수 있습니다.
유형
예시
행 인덱스별
QUERY("table1#1")
행 기본 키별
QUERY("customer/abc@gmail.com")
키-값 필터별
QUERY("order?status=sucess")
여러 열
사용자는 배열을 사용하여 많은 열을 선택할 수 있습니다.
유형
예시
열 배열별
QUERY("order?status=shipping", {"order date", "address", "Cargo weight"})
1차원 참조별
QUERY("order?status=shipping", A1:D1)
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './styles.css';
import { AppFunc } from './app-func';
import { App } from './app-class';
// 1. Functional Component sample
ReactDOM.render(<AppFunc />, document.getElementById('app'));
// 2. Class Component sample
// ReactDOM.render(<App />, document.getElementById('app'));
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-tablesheet";
import { SpreadSheets } from '@mescius/spread-sheets-react';
import '@mescius/spread-sheets-resources-ko';
GC.Spread.Common.CultureManager.culture("ko-kr");
import './styles.css';
export function AppFunc() {
const 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.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: 120 },
{ value: "ProductName", caption: "Product Name", width: 200 },
{ value: "UnitPrice", caption: "Unit Price", width: 120 },
{ value: "UnitsInStock", caption: "Units In Stock", width: 120 },
{ value: "UnitsOnOrder", caption: "Units On Order", width: 130 },
{ value: "=SUM([@UnitsInStock], [@UnitsOnOrder])", caption: "Total Amount", width: 130 },
{ value: "=[@UnitPrice] * SUM([@UnitsInStock], [@UnitsOnOrder])", caption: "Total Price", width: 120 }
]);
myView.fetch().then(function () {
spread.suspendPaint();
sheet.setDataView(myView);
var sheet1 = spread.getSheet(0);
sheet1.setColumnWidth(0, 170);
sheet1.setColumnWidth(1, 95);
sheet1.setColumnWidth(2, 95);
sheet1.setColumnWidth(3, 120);
sheet1.setColumnWidth(4, 170);
sheet1.setColumnWidth(6, 110);
sheet1.setColumnWidth(7, 170);
sheet1.setValue(0, 0, "Product Count:")
sheet1.setFormula(0, 1, "=COUNTA(TableSheet1[ID])");
sheet1.setValue(0, 3, 'Total Price:')
sheet1.setFormula(0, 4, '=SUM(TableSheet1[Total Price])');
//Category Summary
applyTableStyleForRange(sheet1, 3, 0, 9, 5);
sheet1.setValue(2, 0, "Category Summary:")
sheet1.setArray(3, 0, [
["Category", "Product No", "On Order Cost", "Highest Unit Price", "Highest Price Product"]
]);
sheet1.setFormula(4, 0, '=UNIQUE(TableSheet1[Category])');
sheet1.setFormula(4, 1, '=COUNTIF(TableSheet1[Category], A5#)');
sheet1.setFormula(4, 3, '=MAXIFS(TableSheet1[Unit Price], TableSheet1[Category], A5#)');
for (var i = 5; i <= 12; 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[Product Name])');
}
//Out of Stock
sheet1.setValue(2, 6, "Out of Stock:")
applyTableStyleForRange(sheet1, 3, 6, 6, 2);
sheet1.setArray(3, 6, [
["Category", "Product"]
]);
sheet1.setFormula(4, 6, '=FILTER(TableSheet1[Category]:TableSheet1[Product Name], TableSheet1[Units In Stock] = 0)');
//Filters
sheet1.setValue(13, 0, "Category:");
sheet1.setFormula(13, 1, "=A5");
var dv2 = GC.Spread.Sheets.DataValidation.createFormulaListValidator('=$A$5#');
sheet1.setDataValidator(13, 1, dv2);
sheet1.setValue(13, 3, "Category ID:");
sheet1.setFormula(13, 4, '=QUERY("categoryTable?CategoryName="&B14, "Id")');
sheet1.comments.add(13, 4, 'Query the category id.');
applyTableStyleForRange(sheet1, 15, 0, 14, 3);
sheet1.setArray(15, 0, [
["ProductName", "UnitPrice", "UnitsInStock"]
]);
sheet1.setFormula(16, 0, '=QUERY("productTable?CategoryId="&E14, A16:C16)');
sheet1.comments.add(16, 0, 'Use the QUERY function to get data from DataManager.');
spread.setActiveSheetIndex(0);
spread.resumePaint();
});
spread.resumePaint();
}
const 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.light2, options);
sheet.tables.remove(tableName, 2 /* keep style */);
}
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
</SpreadSheets>
</div>
</div>
);
}
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api';
}
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
import * as React from 'react';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-tablesheet";
import { SpreadSheets } from '@mescius/spread-sheets-react';
import '@mescius/spread-sheets-resources-ko';
GC.Spread.Common.CultureManager.culture("ko-kr");
import './styles.css';
const Component = React.Component;
export class App extends Component {
render() {
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
</SpreadSheets>
</div>
</div>
);
}
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.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: 120 },
{ value: "ProductName", caption: "Product Name", width: 200 },
{ value: "UnitPrice", caption: "Unit Price", width: 120 },
{ value: "UnitsInStock", caption: "Units In Stock", width: 120 },
{ value: "UnitsOnOrder", caption: "Units On Order", width: 130 },
{ value: "=SUM([@UnitsInStock], [@UnitsOnOrder])", caption: "Total Amount", width: 130 },
{ value: "=[@UnitPrice] * SUM([@UnitsInStock], [@UnitsOnOrder])", caption: "Total Price", width: 120 }
]);
let _this = this;
myView.fetch().then(function () {
spread.suspendPaint();
sheet.setDataView(myView);
var sheet1 = spread.getSheet(0);
sheet1.setColumnWidth(0, 170);
sheet1.setColumnWidth(1, 95);
sheet1.setColumnWidth(2, 95);
sheet1.setColumnWidth(3, 120);
sheet1.setColumnWidth(4, 170);
sheet1.setColumnWidth(6, 110);
sheet1.setColumnWidth(7, 170);
sheet1.setValue(0, 0, "Product Count:")
sheet1.setFormula(0, 1, "=COUNTA(TableSheet1[ID])");
sheet1.setValue(0, 3, 'Total Price:')
sheet1.setFormula(0, 4, '=SUM(TableSheet1[Total Price])');
//Category Summary
_this.applyTableStyleForRange(sheet1, 3, 0, 9, 5);
sheet1.setValue(2, 0, "Category Summary:")
sheet1.setArray(3, 0, [
["Category", "Product No", "On Order Cost", "Highest Unit Price", "Highest Price Product"]
]);
sheet1.setFormula(4, 0, '=UNIQUE(TableSheet1[Category])');
sheet1.setFormula(4, 1, '=COUNTIF(TableSheet1[Category], A5#)');
sheet1.setFormula(4, 3, '=MAXIFS(TableSheet1[Unit Price], TableSheet1[Category], A5#)');
for (var i = 5; i <= 12; 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[Product Name])');
}
//Out of Stock
sheet1.setValue(2, 6, "Out of Stock:")
_this.applyTableStyleForRange(sheet1, 3, 6, 6, 2);
sheet1.setArray(3, 6, [
["Category", "Product"]
]);
sheet1.setFormula(4, 6, '=FILTER(TableSheet1[Category]:TableSheet1[Product Name], TableSheet1[Units In Stock] = 0)');
//Filters
sheet1.setValue(13, 0, "Category:");
sheet1.setFormula(13, 1, "=A5");
var dv2 = GC.Spread.Sheets.DataValidation.createFormulaListValidator('=$A$5#');
sheet1.setDataValidator(13, 1, dv2);
sheet1.setValue(13, 3, "Category ID:");
sheet1.setFormula(13, 4, '=QUERY("categoryTable?CategoryName="&B14, "Id")');
sheet1.comments.add(13, 4, 'Query the category id.');
_this.applyTableStyleForRange(sheet1, 15, 0, 14, 3);
sheet1.setArray(15, 0, [
["ProductName", "UnitPrice", "UnitsInStock"]
]);
sheet1.setFormula(16, 0, '=QUERY("productTable?CategoryId="&E14, A16:C16)');
sheet1.comments.add(16, 0, 'Use the QUERY function to get data from DataManager.');
spread.setActiveSheetIndex(0);
spread.resumePaint();
});
spread.resumePaint();
}
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.light2, options);
sheet.tables.remove(tableName, 2 /* keep style */ );
}
}
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="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/ko/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/ko/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app" style="height: 100%;"></div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: 100%;
height: 100%;
overflow: hidden;
float: left;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.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'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);