【问题标题】:Comparing the 'email' field and delete duplicates in Google Sheets corresponding to the duplicate email columns比较“电子邮件”字段并删除 Google 表格中与重复电子邮件列相对应的重复项
【发布时间】:2018-11-20 05:01:13
【问题描述】:

我正在使用 Google Apps 脚本站点上的此代码示例,它删除了工作表中的重复项,但我需要一些帮助来根据我的需要进行修改。

这是我的数据的样子:https://i.imgur.com/EcUoQpf.png

列标题是:时间、姓名、电子邮件、联系人、流和学院名称。现在,我想删除比较每行的电子邮件 ID 的重复行。

我使用的示例代码是

/**
 * Removes duplicate rows from the current sheet.
 */
function removeDuplicates() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  var newData = [];
  for (i in data) {
    var row = data[i];
    var duplicate = false;
    for (j in newData) {
      if (row.join() == newData[j].join()) {
        duplicate = true;
      }
    }
    if (!duplicate) {
      newData.push(row);
    }
  }
  sheet.clearContents();
  sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}

请帮我解决这个问题。谢谢!

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    我只是通过更改来修复它:

     if (row.join() == newData[j].join()) {
        duplicate = true;
    

    这个:

     if(row[1] == newData[j][1] && row[2] == newData[j][2]){
        duplicate = true;
      }
    

    【讨论】:

      猜你喜欢
      • 2016-08-08
      • 1970-01-01
      • 2014-05-15
      • 2012-05-18
      • 1970-01-01
      • 2013-09-04
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多