有没有方法可以评估存储在单元格中的公式? [英] Is there a way to evaluate a formula that is stored in a cell?

查看:103
本文介绍了有没有方法可以评估存储在单元格中的公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google文档电子表格中,我正在寻找类似于 = EVAL(A1)的内容,其中A1设置为= 1 + 2



我发现在MS Excel中有一个 EVALUATE()函数(这似乎有点棘手,正确使用)。但我在Google文档中找不到任何类似内容。



我还通过函数列表,但找不到任何有用的信息...


<不,在Google表格中没有与Excel的 EVALUATE()等效的功能。



这款软件历史悠久,请参阅此旧文章实例。

如果你只是对简单的数学感兴趣(如你的问题所示),那么可以通过自定义功能

 函数doMath(公式){ 
//删除前导=if
if(formula.charAt(0)==='=')formula = formula.substring(1);
return eval(formula)
}

例如,在另一个单元格中放置 = doMath(A1),它会是 3


In a Google Docs spreadsheet, I'm looking for something like =EVAL(A1) where A1 is set to "=1+2".

I found out that in MS Excel there is a EVALUATE() function (which seems a bit tricky to use properly). But I could not find anything similar in Google Docs.

I also searched through the function list, but could not find anything helpful...

解决方案

No, there's no equivalent to Excel's EVALUATE() in Google Sheets.

There's long history behind this one, see this old post for instance.

If you're just interested in simple math (as shown in your question), that can be done easily with a custom function.

function doMath( formula ) {
  // Strip leading "=" if there
  if (formula.charAt(0) === '=') formula = formula.substring(1);
  return eval(formula)
}

For example, with your A1, put =doMath(A1) in another cell, and it will be 3.

这篇关于有没有方法可以评估存储在单元格中的公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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