-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsGoogSheetGoogCalendarSync
50 lines (42 loc) · 1.46 KB
/
jsGoogSheetGoogCalendarSync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
var calId = "[email protected]";
var sheetName = 'Events';
*/
function addToCal() {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
var sheet = ss.getActiveSheet(),
var data = sheet.getDataRange().getValues(),
var calendar = CalendarApp.getCalendarById('[email protected]');
for (var i = 1, ok = 1, len = data.length; i < len; i++)
{
var title = (data[i][1] + ': '+ data[i][2]),
startDate = data[i][4],
endDate = data[i][5],
eventID = data[i][8],
longDescription = ('Description: ' + data[i][2] + ' by ' + data[i][0] + '\nMore info: ' + data[i][7]),
location = data[i][6],
dateEvents = CalendarApp.getEventsForDay(startDate); //why does this not work?
for (var j = 0, jlen = dateEvents.length; j < jlen; j++)
{
if (dateEvents[j].getTitle() == eventID)
{
ok = 0;
break;
}
}
if (ok) //if ok what?
{
CalendarApp.createAllDayEvent(title, startDate, {description: longDescription, location: location})
//, endDate
.removeAllReminders();
ok = 1;
}
}
}
//add a menu when the spreadsheet is opened
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "updateEventCalendar", functionName: "addToCal"});
sheet.addMenu("UpdateCalendar", menuEntries);
}