Created
June 2, 2017 16:39
-
-
Save richmidwinter/0a511b5ad67d5dbbbed8b93284183a63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Google sheets to calendar. | |
function myFunction() { | |
var sheets = SpreadsheetApp.getActive().getSheets(); | |
var cal = CalendarApp.getCalendarsByName('Meal Plan')[0]; | |
if (cal) { | |
cal.deleteCalendar(); | |
} | |
cal = CalendarApp.createCalendar('Meal Plan', { | |
color: CalendarApp.Color.YELLOW | |
}); | |
var weeklyRecurrence = CalendarApp.newRecurrence().addWeeklyRule().interval(sheets.length - 1); | |
var initialDate = new Date(Date.UTC(2017, 4, 22)); // 22nd May 2017 | |
for (var i = 1; i<sheets.length; i++) { | |
var sheet = sheets[i]; | |
var data = sheet.getDataRange().getValues(); | |
for (var j = 0; j<data.length; j++) { | |
var nameOfMeal = data[j][1]; | |
var startDate = new Date(initialDate.valueOf()); | |
startDate.setDate(startDate.getDate() + ((i-1) * 7 +j)); | |
cal.createAllDayEventSeries(nameOfMeal, startDate, weeklyRecurrence) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment