Created
October 31, 2020 17:29
-
-
Save cczhong11/b7f59371d826742dffa034242722d8c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction() { | |
// add to ui | |
var ui = SpreadsheetApp.getUi(); | |
ui.createMenu("Sync to Calendar") | |
.addItem("Schedule life", "schedule") | |
.addToUi(); | |
} | |
function schedule() { | |
var eventCal = CalendarApp.getCalendarById(xxxxxxx); | |
var spreadsheet = SpreadsheetApp.getActiveSheet(); | |
var data = spreadsheet.getRange("A2:C20").getValues(); | |
for (i = 0; i < data.length; i++) { | |
// print data, see it from https://script.google.com/home/executions | |
console.log(data[i]); | |
var shift = data[i]; | |
var startTime = shift[0]; | |
var endTime = shift[1]; | |
var name = shift[2]; | |
if (name === "") { | |
continue; | |
} | |
// api in https://developers.google.com/apps-script/reference/calendar/calendar-app#createEvent(String,Date,Date) | |
eventCal.createEvent(name, startTime, endTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment