【问题标题】:If else in Google Script [duplicate]如果谷歌脚本中的其他内容[重复]
【发布时间】:2020-04-25 17:01:04
【问题描述】:

我想编写一个谷歌脚本,如果“R”行包含“拒绝”文本,该脚本将删除“N”列中的所有单元格。 我已经编写了这个脚本,但它删除了“N”列中的所有单元格。帮助我解决我的错误或建议 更好的脚本。

function clean0() {
  var app = SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getSheetByName('Tasks');

  for (var i = 2; i < 100; i++) {
    var workingCell = activeSheet.getRange(i, 18).getValue();

    if (workingCell = '0') {
      activeSheet.getRange(i, 14).setValue("a");
    } else {

    }
  }
}

【问题讨论】:

  • if (workingCell = '0')这是作业,使用=====进行比较

标签: javascript for-loop if-statement google-apps-script


【解决方案1】:

正如@VLAZ 所说,您必须使用===== 而不是= 来比较两个值。

来自Comparision operators

console.log(1 == 1);
// expected output: true

console.log('1' == 1);
// expected output: true

console.log(1 === 1);
// expected output: true

console.log('1' === 1);
// expected output: false

对于if (workingCell = '0',它总是返回true,因为它是一个赋值,而不是一个比较。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多