【问题标题】:How to compare two strings in a cell on Google Apps Script如何在 Google Apps Script 上比较单元格中的两个字符串
【发布时间】:2018-05-07 18:28:44
【问题描述】:

我正在尝试找到一种方法来查看电子表格中的单元格并查看下一个值是否等于该值... 这是我当前的代码:

function BTB(name,ng) {
  if(typeof(name) == typeof(ng)) {
    var c = '0';
    Logger.log(c);
  }
}

【问题讨论】:

  • “下一个值”是什么意思?右边的单元格?下面的牢房?替换刚刚编辑的旧值的新值?
  • 对不起右边和下面的值
  • 你为什么使用 typeof?
  • 如何调用函数?您如何将值/对象分配给函数参数?
  • 功能不完整。请结帐Custom functions in Google Sheets

标签: google-apps-script google-sheets custom-function


【解决方案1】:

对函数和变量使用有意义的名称是一个好习惯,因此我将您的BTB() 重命名为compare()。另外,我没有传递参数,而是冒昧地只使用活动单元格。希望它有效!请在尝试以下代码后告诉我:

function compare() {
  var cell = SpreadsheetApp.getActive().getActiveCell(), msg,
      equal = (cell.getValue() === cell.offset(1, 1).getValue()); // to the right and below
  if (equal) msg = 'active cell is same as next'
  else msg = 'active cell is different from next';
  Browser.msgBox(msg)
}

顺便说一句,由于严格的等号===,上面的代码区分了“2”(字符串)和2(数字)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多