Skip to content

Instantly share code, notes, and snippets.

@cczhong11
Created October 31, 2020 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cczhong11/b7f59371d826742dffa034242722d8c2 to your computer and use it in GitHub Desktop.
Save cczhong11/b7f59371d826742dffa034242722d8c2 to your computer and use it in GitHub Desktop.
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