ChatGPT helped me get a WAY better solution…
Here’s my prompt to CHATGPT:
Can you make a Google Script for getting all my Google Calendar events from ALL my google calendars on my account into Google sheets. I want the events name, start date+time end date+time, description and name of calendar the event belongs to.
Here is the answer from CHATGPT:
Certainly! Here’s a Google Apps Script code that retrieves all your Google Calendar events from all your calendars and writes them into a Google Sheets spreadsheet with the event name, start date+time, end date+time, description, and the name of the calendar the event belongs to.
Please follow these steps to set up the script:
- Open a new Google Sheets document.
- Go to “Extensions” in the menu bar and select “Apps Script” to open the Google Apps Script editor.
- Replace the default code in the editor with the following script:
function exportCalendarEventsToSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Calendar Events"); // Change "Calendar Events" to the name of the sheet you want to use
// Clear existing data in the sheet
sheet.clearContents();
// Get all calendars
var calendars = CalendarApp.getAllCalendars();
// Write headers
sheet.appendRow(["Event Name", "Start Date+Time", "End Date+Time", "Description", "Calendar Name"]);
// Iterate through each calendar
for (var i = 0; i < calendars.length; i++) {
var calendar = calendars[i];
var events = calendar.getEvents(new Date(), new Date(2099, 12, 31)); // Adjust the end date as needed
// Iterate through each event
for (var j = 0; j < events.length; j++) {
var event = events[j];
// Get event details
var eventName = event.getTitle();
var startDateTime = event.getStartTime();
var endDateTime = event.getEndTime();
var description = event.getDescription();
var calendarName = calendar.getName();
// Write event details to the sheet
sheet.appendRow([eventName, startDateTime, endDateTime, description, calendarName]);
}
}
}
- Save the script by clicking on the floppy disk icon or pressing
Ctrl + S
.
- Close the Google Apps Script editor.
Now, you can run the script by following these steps:
- Open your Google Sheets document.
- Go to “Extensions” in the menu bar and select “Apps Script.”
- In the Apps Script editor, select the function
exportCalendarEventsToSheet
.
- Click the play button (
) to run the script.
- Grant necessary permissions when prompted.
- Wait for the script to finish executing. It may take some time if you have a large number of events.
Once the script completes, you should see a new sheet named “Calendar Events” (or the name you specified) with all your Google Calendar events listed, including the event name, start date+time, end date+time, description, and the name of the calendar the event belongs to.
Note: You might need to run the script periodically or trigger it automatically if you want to keep the Google Sheets document updated with the latest calendar events.