我正在使用一个脚本,它从日历中提取事件详细信息并将它们添加到电子表格的 A 列和 B 列中,删除任何重复的事件,然后根据日期进行排序。我希望那时我可以让工作人员在 C、D 等列中添加有关这些事件的其他数据。
这似乎工作正常,但是一旦在 C、D 列中添加信息,脚本重复数据删除功能就会停止工作,因为它正在比较整行,而不仅仅是正在导入的内容。
在确定行是否重复并应删除时,是否有一种方法可以调整以下重复数据删除脚本以仅检查 A 列和 B 列?
我已尝试使用本文变体部分中的代码(当前已注释掉)调整:https ://developers.google.com/apps-script/articles/removing_duplicates - 但它似乎仍然不起作用.
感谢您的任何帮助
剧本:
enter code here
//this section retrieves the information from a calendar from a user submitted date until the end of the year
function importEvents(){
var calID = Browser.inputBox("Please enter your google Cal ID", Browser.Buttons.OK_CANCEL);
var startdate = Browser.inputBox("Start date using 1/1/2013 format", Browser.Buttons.OK_CANCEL);
var cal = CalendarApp.getCalendarById(calID);
var events_sheet = SpreadsheetApp.getActiveSheet();
var events = cal.getEvents(new Date(startdate), new Date("1/1/2014"));
var lr = events_sheet.getLastRow();
var eventarray = new Array();
var i = 0; // edited
for (i = 0; i < events.length; i++) {
line = new Array();
line.push(events[i].getStartTime());
line.push(events[i].getTitle());
//Potential more data that I am not getting at this time
// line.push(events[i].getDescription());
// line.push(events[i].getEndTime());
eventarray.push(line);
}
events_sheet.getRange("A"+(lr+1)+":B"+(lr+i)).setValues(eventarray);
//sort ascending dy date
var range = SpreadsheetApp.getActiveSheet().getRange("A3:F2000");
range.sort([{column: 1, ascending: true}]);
//removes duplicate rows
var sheet = SpreadsheetApp.getActiveSheet();
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.join() == newData[j].join()){
duplicate = true;
//This was supposed to only check the first 2 columns, but it doesn't work
//I found this code in the variation section of this tutorial: https://developers.google.com/apps-script/articles/removing_duplicates
//
// if(row[0] == newData[j][0] && row[1] == newData[j][1]){
// duplicate = true;
}
}
if(!duplicate){
newData.push(row);
}
}
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}