캘린더 ID를 입력하고, 시작일과 종료일을 설정해 넣으면 된다.
시작일은 당월 1일로 하고, 현재 일까지 하여 가져오는 예제이다.
function importEvents(){
var startOfDay = new Date();
startOfDay.setUTCHours(0);
startOfDay.setMinutes(0);
startOfDay.setSeconds(0);
startOfDay.setMilliseconds(0);
var endOfDay = new Date(startOfDay.getTime() + 24 * 60 * 60 * 1000);
startOfDay.setDate(1);
var Calendar = CalendarApp.getCalendarById("캘린더ID");
var events = Calendar.getEvents(startOfDay, endOfDay)
var events_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ImportedEvents");
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].getTitle());
line.push(events[i].getDescription());
line.push(events[i].getStartTime());
line.push(events[i].getEndTime());
eventarray.push(line);
}
events_sheet.getRange('A1:D' + (i)).setValues(eventarray);
}
댓글 달기