From 5c5f2cb1e62e02e0f851ddcfc4ec64ad0e0a9971 Mon Sep 17 00:00:00 2001 From: kdevilpf <459373440@qq.com> Date: Mon, 14 Dec 2020 08:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86EVALUATE=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/function/functionImplementation.js | 19 +++++++++++-------- src/global/formula.js | 5 +++++ src/locale/en.js | 4 ++-- src/locale/es.js | 4 ++-- src/locale/zh.js | 6 +++--- src/locale/zh_tw.js | 14 ++++++++++++++ 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/function/functionImplementation.js b/src/function/functionImplementation.js index 5c1b71b..a02ad33 100644 --- a/src/function/functionImplementation.js +++ b/src/function/functionImplementation.js @@ -27562,19 +27562,22 @@ const functionImplementation = { } try { + var cell_r = window.luckysheetCurrentRow; + var cell_c = window.luckysheetCurrentColumn; + var sheetindex_now = window.luckysheetCurrentIndex; //公式文本 var strtext = func_methods.getFirstValue(arguments[0]).toString(); if(valueIsError(strtext)){ return strtext; } - - //if (!window.luckysheet_function.ISIDCARD.f(UUserCard)) { - // return formula.error.v; - //} - //匹配简单公式,只能包含 空格 数字-+*/.() - var formulastr = /[ \d\+\*\-\/\(\)\.]+/; - var strtext2=strtext.match(formulastr)[0]; - return eval(strtext2); + //在文本公式前面添加= + if(strtext.trim().indexOf('=')!=0) + { + strtext ='='+strtext; + } + //console.log(strtext); + var result_this = formula.execstringformula(strtext,cell_r,cell_c,sheetindex_now); + return result_this[1]; } catch (e) { var err = e; diff --git a/src/global/formula.js b/src/global/formula.js index 61f0929..e1a7b58 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -5758,6 +5758,11 @@ const luckysheetformula = { return false; } }, + //供function/functionImplementation.js的EVALUATE函数调用。 + execstringformula: function (txt, r, c, index) { + let _this = this; + return this.execfunction(txt, r, c, index); + }, functionResizeData: {}, functionResizeStatus: false, functionResizeTimeout: null, diff --git a/src/locale/en.js b/src/locale/en.js index 1af6071..77fe87c 100644 --- a/src/locale/en.js +++ b/src/locale/en.js @@ -8820,8 +8820,8 @@ export default { "m": [1, 1], "p": [{ "name": "expression", - "example": '"5*6"', - "detail": "Formula or expression only supports numbers+-/*.()", + "example": '"A1+5*2^2"', + "detail": "Formula or expression", "require": "m", "repeat": "n", "type": "rangeall" diff --git a/src/locale/es.js b/src/locale/es.js index a7cd0fa..4ee78b2 100644 --- a/src/locale/es.js +++ b/src/locale/es.js @@ -8820,8 +8820,8 @@ export default { "m": [1, 1], "p": [{ "name": "expression", - "example": '"5*6"', - "detail": "Formula or expression only supports numbers+-/*.()", + "example": '"A1+5*2^2"', + "detail": "Formula or expression", "require": "m", "repeat": "n", "type": "rangeall" diff --git a/src/locale/zh.js b/src/locale/zh.js index 3914ad8..55270ea 100644 --- a/src/locale/zh.js +++ b/src/locale/zh.js @@ -9040,13 +9040,13 @@ export default { { "n": "EVALUATE", "t": "3", - "d": "对以文字表示的一个公式或者表达式求值,并返回结果", + "d": "对以文字表示的公式或者表达式求值,并返回结果。", "a": "根据文字公式或者表达式求值。", "m": [1, 1], "p": [{ "name": "公式", - "example": '"5*6"', - "detail": "公式或表达式仅支持数字+-/*.()", + "example": '"A1+5*2^2"', + "detail": "公式或表达式", "require": "m", "repeat": "n", "type": "rangeall" diff --git a/src/locale/zh_tw.js b/src/locale/zh_tw.js index 8d89824..bec4596 100644 --- a/src/locale/zh_tw.js +++ b/src/locale/zh_tw.js @@ -9038,6 +9038,20 @@ export default { 'repeat' : 'n', 'type' : 'rangenumber' }] + },{ + 'n': 'EVALUATE', + 't': '3', + 'd': '對以文字表示的公式或者表達式求值,並返回結果。', + 'a': '根據文字公式或者表達式求值。', + 'm': [1, 1], + "p": [{ + "name": "公式", + "example": '"A1+5*2^2"', + "detail": "公式或表達式", + "require": "m", + "repeat": "n", + "type": "rangeall" + }] }, ], toolbar: {