工作表函数用于实数除法(即,/) [英] Worksheet function for division of real numbers (ie, /)

查看:70
本文介绍了工作表函数用于实数除法(即,/)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在中找不到实数(即/)的除法工作表功能.因此,要评估=SUM(2,SUM(30,40)/3),我们不能使用一个表达式ctx.workbook.functions.sum(1,ctx.workbook.functions.sum(30,40)/3); 我们必须做两次ctx.sync:

I have not found division of real numbers (ie, /) in worksheet functions. As a consequence, to evaluate =SUM(2,SUM(30,40)/3), we cannot use one expression ctx.workbook.functions.sum(1,ctx.workbook.functions.sum(30,40)/3); we have to do ctx.sync two times:

function test () {
    Excel.run(function (ctx) {
        var result = ctx.workbook.functions.sum(30,40);
        var result2;
        result.load();
            return ctx.sync()
                .then(function () {
                    result2 = ctx.workbook.functions.sum(1,result.value/3);
                    result2.load(); })
                .then(ctx.sync)
                .then(function () {
                    console.log(result2.value); });
    }); 
}

这意味着,如果一个表达式中有多个/,我们必须使用更多的ctx.sync对其进行评估,这非常繁琐(尤其是难以自动构造).

That means, if there are several / in one expression, we have to use even more ctx.sync to evaluate it, which is very tedious (and especially hard to be automatically constructed).

因此找到工作表函数或/的变通办法非常好,这样我们仍然可以一步评估一个包含/的表达式.

So it would be really great to either find the worksheet function or a workaround for /, so that we could still evaluate an expression containing / in one step.

PS:+*-似乎都没有工作表功能,但是我们可以使用变通方法:对于+来说是sum,对于*来说是product. sum(..., product(-1, ...)表示-.

PS: it seems that there is no worksheet function for +, *, - either, but we could use workarounds: sum for +, product for *, and sum(..., product(-1, ...) for -.

推荐答案

一种解决方案是将product函数和power函数与指数-1结合使用.即使分母(除数)是一个变量而不是一个常数,此解决方案仍然有效.

One solution is to use a combination of the product function and the power function with the exponent -1. This solution will work even if the denominator (divisor) is a variable and not a constant.

var myNumerator = 888, myDenominator = 4;
var funcs = ctx.workbook.functions;
var result = funcs.product(myNumerator,funcs.power(myDenominator,-1));

在评估=SUM(2,SUM(30,40)/3)的特定示例中,代码为:

In your specific example to evaluate =SUM(2,SUM(30,40)/3), the code would be:

result = funcs.sum(2,funcs.product(funcs.sum(30,40),funcs.power(3,-1)));

这篇关于工作表函数用于实数除法(即,/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆