수식 또는 관련 필드별 그룹화

테이블 시트는 필드뿐 아니라 수식관련 필드도 그룹 또는 슬라이스 열로 지원합니다.

수식 또는 관련 필드를 그룹 옵션으로 설정할 수 있습니다. 슬라이스 열은 수식 및 관련 필드를 동일한 방법으로 지원할 수 있습니다. 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의 조합에만 사용해야 합니다.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> </gc-spread-sheets> </div> </template> <script setup> import GC from "@mescius/spread-sheets"; import { ref } from "vue"; import "@mescius/spread-sheets-tablesheet"; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import "@mescius/spread-sheets-vue"; const spreadRef = ref(null); function initSpread(spread) { spreadRef.value = 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(); } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api'; } var baseApiUrl = getBaseApiUrl(); function getApiUrl(tableName) { return baseApiUrl + "/" + tableName; } </script> <style scoped> #app { height: 100%; } .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; margin: 0; } </style>
<!DOCTYPE html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>SpreadJS VUE</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/spread/source/data/orderDataSource.js" type="text/javascript"></script> <script src="$DEMOROOT$/ko/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> var System = SystemJS; System.import("./src/app.js"); System.import('$DEMOROOT$/ko/lib/vue3/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'tiny-emitter': 'npm:tiny-emitter/index.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-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js' }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);