수식 또는 관련 필드를 그룹 옵션으로 설정할 수 있습니다.
슬라이스 열은 수식 및 관련 필드를 동일한 방법으로 지원할 수 있습니다.
DATEPART 수식을 사용하여 필드를 날짜 형식별로 그룹화할 수 있습니다. 구문은 다음과 같습니다.
인수
설명
date_value
(필수) 날짜 값.
format_string
(필수) 날짜의 서식 문자열.
[week_num_type]
(선택 사항) WEEKNUM의 두 번째 인수와 동일.
DATEPART 수식의 서식 문자열 및 샘플:
서식
결과
설명
yyyyQ
20214
숫자: 한 자릿수(분기 숫자/이름)
yyyyQQ
202104
숫자: 두 자릿수 + 제로 패드
yyyyQQQ
2021Q4
약어
yyyy QQQQ
2021 4분기
넓게
YYYY w
2021 8
숫자: 최소 자릿수(연도의 주)(숫자). 패턴에서 연도와 함께 사용할 때 연도 필드의 경우 'Y' 사용.)
YYYY ww
2021 08
숫자: 두 자릿수, 필요한 경우 제로 패드
MM-yyyy
09-2021
셀 서식 지정에서 부분 날짜 포맷터 제공
CALCULATE 및 REMOVEFILTERS 수식을 사용하면 그룹 컨텍스트를 확장할 수 있습니다. 구문은 다음과 같습니다.
인수
설명
formula_string
(필수) 수식은 expand_context의 컨텍스트로 평가합니다.
expand_context
(필수) expand_context는 REMOVEFILTERS의 컨텍스트입니다.
인수
설명
[group_field_string]
(선택 사항) 그룹 필드는 확장되는 범위를 나타냅니다.
CALCULATE 수식은 summaryFields 섹션에서만 사용해야 하며, REMOVEFILTERS는 REMOVEFILTERS와 CALCULATE의 조합에만 사용해야 합니다.
/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
import { Component, NgModule, enableProdMode } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@mescius/spread-sheets-angular';
import GC from '@mescius/spread-sheets';
import "@mescius/spread-sheets-tablesheet";
import '@mescius/spread-sheets-resources-ko';
GC.Spread.Common.CultureManager.culture("ko-kr");
import './styles.css';
declare let orderDataSource: any;
function getBaseApiUrl() {
return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api';
}
var baseApiUrl = getBaseApiUrl();
function getApiUrl(tableName: string) {
return baseApiUrl + "/" + tableName;
}
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
hostStyle = {
width: 'calc(100% - 280px)',
height: '100%',
overflow: 'hidden',
float: 'left'
};
spread: GC.Spread.Sheets.Workbook;
constructor() {
}
initSpread($event: any) {
let spread = this.spread = $event.spread;
spread.suspendPaint();
spread.clearSheets();
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
//init a data manager
var dataManager = spread.dataManager();
var ordersTable = dataManager.addTable("ordersTable", {
remote: {
read: {
url: getApiUrl("Order")
}
},
schema: {
columns: {
orderDate: { dataType: "date" },
requiredDate: { dataType: "date" },
shippedDate: { dataType: "date" }
}
}
});
var customersTable = dataManager.addTable("customersTable", {
remote: {
read: {
url: getApiUrl("Customer")
}
}
});
dataManager.addRelationship(ordersTable, "CustomerId", "Customers", customersTable, "Id", "Orders");
var view = ordersTable.addView("orderView", [
{ value: "Id", width: 65 },
{ value: "OrderDate", width: 100 },
{ value: "RequiredDate", width: 120 },
{ value: "ShippedDate", width: 110 },
{ value: "ShipVia", width: 110 },
{ value: "Freight", width: 80 },
{ value: "ShipName", width: 200 },
]);
//init a table sheet
var sheet = spread.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet);
view.fetch().then(function () {
sheet.setDataView(view);
sheet.groupOutlinePosition(GC.Spread.Sheets.TableSheet.GroupOutlinePosition.none);
sheet.groupBy([
{
caption: "Company Name", field: "Customers.CompanyName", width: 160,
},
{
caption: "Year Quarter", field: '=DATEPART([@OrderDate],"yyyy-QQQ")', width: 160,
},
{
caption: "Ship Via", field: 'ShipVia', style: { formatter: '=SWITCH(@,1,"Speedy Express", 2,"United Package", 3, "Federal Shipping","")' }, width: 135,
summaryFields: [
{
caption: "Freight", width: 100,
formula: "=SUM([Freight])",
},
{
caption: "Company Ratio", width: 130, style: { formatter: "0.00%" },
formula: '=SUM([Freight]) / CALCULATE( SUM([Freight]), REMOVEFILTERS("ShipVia","=DATEPART([@OrderDate],""yyyy-QQQ"")"))', // ratio of sum of freight under freight level to sum of freight under year quarter
},
{
caption: "% Grand Total", width: 120, style: { formatter: "0.00%" },
formula: '=SUM([Freight]) / CALCULATE( SUM([Freight]), REMOVEFILTERS())', // ratio of sum of freight under freight level to sum of freight under all records
}
]
},
{
caption: "Freight Level", width: 135,
field: '=IFS([@Freight]<30,0,AND([@Freight]>=30,[@Freight]<60),1,[@Freight]>60,2)',
style: { formatter: '=SWITCH(@,0,"Low",1,"Medium",2,"High","no match")' },
}
]);
});
spread.resumePaint();
}
}
@NgModule({
imports: [BrowserModule, 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$/ko/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/spread/source/data/orderDataSource.js" type="text/javascript"></script>
<!-- Polyfills -->
<script src="$DEMOROOT$/ko/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/ko/angular/node_modules/zone.js/fesm2015/zone.min.js"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/ko/angular/node_modules/systemjs/dist/system.js"></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$/ko/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)">
</gc-spread-sheets>
</div>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.optionContainer {
float: right;
width: 280px;
}
.optionContainer input {
margin-right: 5px;
}
(function (global) {
System.config({
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// 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': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js',
'@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js',
'@mescius/spread-sheets-angular': 'npm:@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);