当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - What's the best way to compare two columns of data in Google Sheets and output ONLY the non-matching using Google Scripts?

问题描述:

I have two columns of similar unique data (Column A and Column B) and on the third (Column C), I would like to output data, where it is in Column B but not in Column A.

I would like to do this in Google Scripts and have tried writing my own if statements, looping it but without luck.

Can someone please point me to the right direction?

网友答案:

I actually do the same thing on a sheet I use at work. It looks at Col A, and Col C, and the ones from col A that are not in Col C will show up in Col E.

function onOpen() {
  SpreadsheetApp.getUi().createMenu("CD Report")
  .addItem("Agreement Report", "agreementReport")
  .addToUi();
}

function agreementReport(){
  var as = SpreadsheetApp.getActive();
  var sheet = as.getSheetByName("15-16 1:1 agreement");

  var handedIn = sheet.getSheetValues(2, 1, sheet.getLastRow(), 1);
  var stuNames = sheet.getSheetValues(2, 3, sheet.getLastRow(), 1);
  var list = []; 

  for (i in stuNames){
    var curName = stuNames[i][0];
    var exists = false;

    for (j in handedIn){
      var curCheck = handedIn[j][0];
      if (curCheck == curName){
        exists = true;
        break;
      }
    } // end for j
    if (exists == false){
      list.push([curName]);
    } 
  } // end for i

  sheet.getRange(2, 5, list.length, 1).setValues(list);

} // end agreementReport
分享给朋友:
您可能感兴趣的文章:
随机阅读: