首页 > 解决方案 > 如何比较单元格<->字符串的值

问题描述

我正在寻找将单元格的值与字符串进行比较。(在谷歌脚本中)

function MyMovingTrigger() {
  var ss = SpreadsheetApp.openById("MYIDHERE"); 
  var sheet = ss.getSheetByName("SHEETNAMEHERE");

  if(sheet.getRange('B2').getValue()=="TRUE") { 
    //more code here
  }
}

//The value in B2 is the following:
//this will either display "TRUE" or "FALSE"
=ISREF(INDIRECT("Copy of Empty"&"!C1"))

我得到的错误如下: ReferenceError: Function function getValue() {/* */} can't be used as the left-hand side of assignment or as an operand of ++ or -- operator. 在 MyMovingTrigger(代码:8)

标签: google-apps-script

解决方案


你可以试试这个:

if(sheet.getRange('B2').getValue() == true) { 

即去掉 TRUE 周围的引号并放入小写字母。


推荐阅读