함수 참조

SpreadJS는 함수 참조('eta reduced lambda'라고도 함)를 지원합니다. 이 기능은 불필요한 추상화를 없애고 가능한 경우 약어 구문을 사용하여 함수를 간소화합니다. 아래 데모는 이 기능을 사용하는 방법에 대한 몇 가지 예를 보여줍니다.

설명
app.vue
index.html

사용자 정의 이름에 함수 참조 사용

함수 이름으로 콘텐츠가 있는 사용자 정의 이름을 정의할 수 있습니다. 그런 다음 수식에 사용할 수 있습니다.

spread.addCustomName("op","SUM");
sheet.setFormula(0,0,"op(B1:B5)");

함수 참조를 LAMBDA 함수 매개변수로 사용

LAMBDA 함수가 허용되는 경우 LAMBDA 함수 매개변수를 함수 이름으로 사용할 수 있습니다.

sheet.setFormula(0,0,"=LAMBDA(op,op(123))(SUM)");
sheet.setFormula(1,0,"=MAP(B1:C3,ABS)");
sheet.setFormula(2,0,"=BYCOL(B1:C3,SUM)");
sheet.setFormula(3,0,"=BYROW(B1:C3,SUM)");
sheet.setFormula(4,0,"=MAKEARRAY(3, 3, SUM)");
sheet.setFormula(5,0,"=REDUCE(True, B1:C2, AND)");
sheet.setFormula(6,0,"=SCAN(1, B1:C2, COUNT)");
sheet.setFormula(7,0,"=GROUPBY(B2:B34,D2:D34,SUM)");

LET name_value에 함수 참조 사용

name_value를 함수 참조로 정의한 후 LET 함수에서 사용할 수 있습니다.

sheet.setFormula(0,0,"=LET(op,SUM,op(B1:B5))");

사용자 정의 함수 참조

사용자 정의 함수를 정의하여 위의 사용 사례에 사용할 수 있습니다.

function IsNegativeFunction() {
    this.name = "ISNEGATIVE";
    this.maxArgs = 1;
    this.minArgs = 1;
}
IsNegativeFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
IsNegativeFunction.prototype.evaluate = function (arg) {
    if (parseInt(arg)<0) {
        return true;
    }
    return false;
};
spread.addCustomFunction(new IsNegativeFunction());
sheet.setFormula(4, 2, "=MAP(A1:C3,ISNEGATIVE)");
사용자 정의 이름에 함수 참조 사용 함수 이름으로 콘텐츠가 있는 사용자 정의 이름을 정의할 수 있습니다. 그런 다음 수식에 사용할 수 있습니다. 함수 참조를 LAMBDA 함수 매개변수로 사용 LAMBDA 함수가 허용되는 경우 LAMBDA 함수 매개변수를 함수 이름으로 사용할 수 있습니다. LET name_value에 함수 참조 사용 name_value를 함수 참조로 정의한 후 LET 함수에서 사용할 수 있습니다. 사용자 정의 함수 참조 사용자 정의 함수를 정의하여 위의 사용 사례에 사용할 수 있습니다.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet></gc-worksheet> </gc-spread-sheets> </div> </template> <script setup> import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); function initSpread (spread) { let sd = data; if (sd.length > 0) { if (!spread) { return; } spread.suspendPaint(); spread.fromJSON(sd[0]); spread.calculate(); spread.resumePaint(); } } </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$/ko/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <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 src="$DEMOROOT$/spread/source/data/eta-lambda.js" type="text/javascript"></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: { '@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', '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", }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);