数式

テーブルシートは、階層データで組み込み数式を使用できます。

データソースが階層的データの場合、スキーマのデータフィールドに数式を構成することができます。 また、この数式は子階層を持つデータの場合のみ呼び出されます。 数式を使用する時は、集計された親レコードと子レコードは同じフィールドに存在されています。 階層の集計フィールドのオプション: 以下のサンプルは、階層の集計フィールドを定義します: 組み込み数式 組み込み数式は、階層の集計フィールドと階層の計算列で使用されます。 CHILDREN 次の数式は、親レコードまで levelOffset ステップの子レコードの fieldName の値を取得します。 レベルオフセットは現在のレコードと最上位の子階層との差より大きい場合、親階層ではなく、最下位の子階層の値を返します。 ONLYCHILDREN 次の数式は、親階層でない子レコードの fieldName の値を取得します。 PARENT 次の数式は、現在のレコードまで levelOffset ステップの親レコードの fieldName の値を取得します。 レベルオフセットは現在のレコードと最上位の親階層との差より大きい場合、最上位の親階層の値を返します。 現在のレコードは既に最上位の親階層である場合、何も返しません。 LEVEL 次の数式は、現在のレコードの階層レベルを取得します。 LEVELROWNUMBER 次の数式は、親スコープにある現在のレコードの行番号を取得します。
<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-ja'; GC.Spread.Common.CultureManager.culture("ja-jp"); import "@mescius/spread-sheets-vue"; const spreadRef = ref(null); function initSpread(spread) { spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; spread.clearSheets(); var dataManager = spread.dataManager(); initHierarchyFormulas(spread, dataManager); } function initHierarchyFormulas(spread, dataManager) { var table = dataManager.addTable("Table", { remote: { read: { url: getBaseApiUrl() + "/Hierarchy_Formula" } }, schema: { hierarchy: { type: 'Parent', column: 'parent', summaryFields: { 'budget': '=SUM(CHILDREN(1,"budget"))' } }, columns: { id: { isPrimaryKey: true, }, }, } }); var sheet = spread.addSheetTab(0, "HierarchyFormula", GC.Spread.Sheets.SheetType.tableSheet); sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); sheet.options.allowAddNew = false; table.fetch().then(function () { var myView = table.addView("myView", [ { value: '=CONCAT([@department]," (L",LEVEL(),"-",LEVELROWNUMBER(),")")', caption: 'Department', width: 265, outlineColumn: true }, { value: "budget", width: 100, caption: 'Budget' }, { value: '=IF(LEVEL()=0,"",[@budget]/PARENT(1,"budget"))', width: 120, caption: 'Percentage', style: { formatter: '0.00%' } }, { value: "location", width: 100, caption: 'Location' }, { value: "phone", width: 150, caption: 'Phone' }, { value: "country", width: 100, caption: 'Country' }, ]); spread.suspendPaint(); sheet.setDataView(myView); spread.resumePaint(); }); } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/demos\//)[0] + 'server/api'; } </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; } </style>
<!DOCTYPE html> <html lang="en" 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$/ja/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/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$/ja/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-ja': 'npm:@mescius/spread-sheets-resources-ja/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);