Pull Google Calendar data into Google Sheets using Apps Script

This post was originally published in our community forum.

Objective : This guide demonstrates how to use Google Apps Script to pull data from Google Calendar and display them in a Google Sheet. This process allows you to automate the retrieval of calendar events and manage them directly within a spreadsheet.

Create a New Google Sheet: Open Google Sheets and create a new spreadsheet or open an existing one where you want the calendar data to be displayed.

Open Apps Script: In your Google Sheet, click on Extensions > Apps Script.

Insert the Script: In your Apps Script project, you’ll have two files: Code.gs and props.gs. Delete any existing code in the script editor and replace it with the code snippet provided below. Copy the provided code snippet for Code.gs and props.gs into their respective files.

props.gs

const emailIds = [
  '' // Include here the email address
];

Code.gs

function fetchCalendarData() {

  // Get the active sheet
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.clear();  // Clear any previous content

  sheet.appendRow(["Meeting ID", "Name", "Attendees", "Duration", "Video Link"]);     // Set headers

  // Loop through each email ID
  emailIds.forEach(email => {
    const events = CalendarApp.getCalendarById(email).getEvents(new Date('start_date'), new Date()); 
    // Loop through events and write them to the sheet
    events.forEach(event => {
      const eventId = event.getId();
      const eventName = event.getTitle();
      const attendees = event.getGuestList().map(guest => guest.getEmail()).join(', ');
      const duration = (event.getEndTime() - event.getStartTime()) / (1000 * 60); 
      let videoLink = "";
      const description = event.getDescription();
      if (description) {
        const meetLinkRegex = /https:\/\/calendly\.com\/events\/[\w-]+\/google_meet/i; // Regex to match Video link
        const match = description.match(meetLinkRegex);
        if (match) {
          videoLink = match[0]; 
        }
      } 
      sheet.appendRow([eventId, eventName, attendees, duration, videoLink]);
    });
  });

  Logger.log("Calendar data has been fetched and updated in the sheet.");
}

Update Email IDs: In props.gs, add the email ID of the calendar you want to pull data from. You can adjust the date range by modifying the start_date in the code.gs file.

Execute the script: You might be prompted to authorize the script to access your calendar and spreadsheet. After running the script, your Google Sheet should populate with the event data from the specified Google Calendar.

By following these steps, you can easily automate the process of pulling calendar data into your Google Sheets, making it easier to manage and analyze your schedule.

You may also like…

google sheets features and formulas

How to find nominal interest rate using Google Sheets

Sarah is a young professional making significant financial decisions. From credit cards to mortgages, student loans, and investment...
google sheets features and formulas

Using the PROPER function to capitalize the first letter of each word in Google Sheets

Note: This post was originally published in our community forum. Ever found yourself needing to clean up a list of names, titles, or any...
google sheets features and formulas

Filter values in a column which are not in another column

Note: This post was originally published in our community forum. Hey everyone! 👋 Check out this handy formula for filtering values from...