【问题标题】:Dynamic conditions in IF function in Google SheetsGoogle表格中IF函数中的动态条件
【发布时间】:2021-07-30 23:59:24
【问题描述】:

我使用的是 Google 表格,但遇到了以下问题: 有没有办法将 IF 函数中的逻辑条件保存到单元格中? 比如我们有这个函数:

=IF(B1>0; "正"; "负")

我能否以某种方式将条件“B1>0”保存到单元格 A1 中并像这样使用:

=IF(A1; "正"; "负")

显然我不能那样做,因为 A1 不是布尔值。有没有办法将其转换为布尔值或以任何其他方式保存该条件?

提前致谢

【问题讨论】:

    标签: if-statement google-sheets boolean dynamic-variables


    【解决方案1】:

    放入A1

    =B1>0
    

    A1会根据B1中的值显示真假,然后就可以写了

    =IF(A1; "Positive"; "Negative")
    

    如果你只想存储条件,放入A1

    =">0"
    

    然后写

    =evaluate(B1&A1)
    

    带有自定义功能

    function evaluate( formula ) {
      if (formula.charAt(0) === '=') formula = formula.substring(1);
      return eval(formula)
    }
    

    因为evaluate() 在谷歌表格中不存在

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2021-11-24
      • 2021-11-18
      相关资源
      最近更新 更多