Get Calendar Events into your Spreadsheet using the Calendar API and Google Apps Script

What is the Google Calendar API?

Step 1: Sample Google Sheet

Step 2: Add the Google Calendar API

Step 3: Write the Automation Script

function create_Events(){
(1) var ss = SpreadsheetApp.getActiveSpreadsheet();
(2) var sheet = ss.getSheetByName("GetEvents");
(3) var id_cal = sheet.getRange(“C2”).getValue();
(4) var cal= CalendarApp.getCalendarById(id_cal);
(1)   var start_time = sheet.getRange(“G2”).getValue();
(2) var end_time = sheet.getRange(“H2”).getValue();
(3) var events = cal.getEvents(new Date(start_time), new Date(end_time));
for(var i = 0;i<events.length;i++){
var title = events[i].getTitle();
var start_time = events[i].getStartTime();
var end_time = events[i].getEndTime();
var loc = events[i].getLocation();
var des = events[i].getDescription();
var vis = events[i].getVisibility();
sheet.getRange(i+5,1).setValue(title);
sheet.getRange(i+5,2).setValue(start_time);
sheet.getRange(i+5,3).setValue(end_time);
sheet.getRange(i+5,4).setValue(loc);
sheet.getRange(i+5,5).setValue(des);
sheet.getRange(i+5,6).setValue(vis);
}
Logger.log("Events have been added to the Spreadsheet");
}

Step 4: Check the Output

Summary

Currently pursuing B Tech at MPSTME. Technical Blogger, interested in Google Workspace. Hope to remain a life long student.