Google Apps脚本:为什么相等的字符串/值会不相等

时间:2015-08-02 06:50:44

标签: javascript google-apps-script

我在谷歌应用程序脚本功能中有相同的字符串,并且无法找出原因。论坛上对这个问题的其他答案还有我还不了解的其他语言。这是代码:

function testForMatch() {
  var ss = SpreadsheetApp.getActive();
  var masterSheet = ss.getSheetByName('Leaderboard');
  var masterLength = masterSheet.getMaxRows() - 3;
  var masterData = masterSheet.getRange(4, 2, masterLength).getValues();      //gets all the student names from the leaderboard

  var titleSheet = ss.getSheetByName('Title - Standard scores');
  var titleLength = titleSheet.getMaxRows() -3;
  var titleData = titleSheet.getRange(4, 2, titleLength).getValues();    //gets all the student names from the standard score sheet

  for ( i = 0; i < masterLength; i ++) {
    if(masterData[i] != titleData[i]) {
      var row = i + 1;
      var error = "Uh oh! It looks like " + masterData[i] + " and " + titleData[i] + " do not match in row " + row;
      var ui = SpreadsheetApp.getUi();
      var response = ui.alert(error);
    }
  }
}

即使我只是在匹配的单元格中输入简单的字符串,它也会告诉我它们不匹配。同样对于数字。

我唯一可以想到的是我的脚本实际上并没有比较这些值。如果这是真的,我该怎么做才能做到这一点?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

if(masterData[i][0] != titleData[i][0]) {

...会比较单元格值