表 1
Timestamp |Name | Shift.....| Date....| Letter..|
19/05/2016 15:44:46|Mark | Swap | 02/AUG | S |
Timestamp2 |Ivon | Give away | 25/ AUG | G |
Timestamp3 |Laura| Take | 01/AUG | A |
Timestamp4 |Ann | Take | 02/AUG | A |
Timestamp5 |Ann | Give away | 03/AUG | G |
Timestamp6 |Laura| Delete | 01/AUG | D |
由于这是一个谷歌表,我正在尝试运行以下脚本来删除与名称和日期列匹配的行。EG Laura 在 01AUG 的同一日期有 2 个条目。因此,我希望删除两行。我正在尝试以下脚本,但它不起作用。
function removeDuplicates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Form responses 2");
var data = sheet.getDataRange().getValues();
var newData = new Array();
for(i in data){
var row = data[i];
var duplicate = false;
for(j in newData){
if( row[0] == newData[j][1] && row[1] == newData[j][3]){
duplicate = true;
}
}
if(!duplicate){
newData.push(row);
}
}
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}