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

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

问题描述

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

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

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

I found out that in MS Excel there is an 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...

推荐答案

不,Google 表格中没有与 Excel 的 EVALUATE() 等效的方法.

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)
}

例如,对于您的 A1,将 =doMath(A1) 放在另一个单元格中,它将是 3.

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

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

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