How To Create Calendar Event From Google Sheets

In this tutorial, you will learn how to create your own calendar event from Google Sheets data.

How To Create Calendar Event From Google Sheets

If you manage a calendar of events, you may find yourself needing to manually enter events into your personal or team calendar. This can be a tedious and time-consuming task, especially when newly scheduled events have to be added on a daily basis.

Fortunately, there is a way to quickly create calendar events from a Google Sheets table. This can save you time, as all you have to do is enter the event data once into the spreadsheet and then generate the calendar events from there.

Using Google Apps Script, we can create a function that will take a row of data from Google Sheets, and create a corresponding calendar event.

In this guide, we’ll show you how to create calendar events from Google Sheets using custom Apps Script code.

How To Add a Calendar Event From a Spreadsheet Using Apps Script

Here’s how to add a calendar event from a spreadsheet using Apps Script.

Step 1

Before adding custom Apps Script code to our spreadsheet, we will need to find the calendar ID of our target calendar.

Log in to your Google Calendar account and select the calendar you want to send events to. Click on the icon seen below to access additional options for the selected calendar.

Step 2

Scroll down until you see the Integrate calendar section. Copy the text labeled as ‘Calendar ID’.

Step 3

In your main Google Sheets spreadsheet, add a table that will hold the necessary information you need for creating an event. The table should have a column for the event start time, event end time, and event name. You may also specify the calendar ID to send the event to. This may be useful if your use case requires sending events to more than one calendar.

In the example above, we want to schedule the event ‘Apps Script Crash Course’ in a specified time.

Step 4

After setting up our template, we’ll now proceed to adding custom Apps Script code to actually create the event in our calendar.

Click on the Apps Script option under the Extensions menu.

Step 5

An Apps Script editor should appear in a new tab. We’ll label our new project Add_To_Calendar.

Click on the Code.gs file and add the following function to the code editor:

function add_events_to_calendar() {

var spreadsheet = SpreadsheetApp.getActiveSheet();

var calendar_ID = spreadsheet.getRange(“B1”).getValue();

}

The code above simply retrieves the calendar ID specified in cell B1 and stores the value in a new variable.

Step 6

Next, we’ll need to create a reference to the calendar with the matching calendar_id. We can accomplish this with the following code:

var event_Cal = CalendarApp.getCalendarById(calendar_ID);

Next, we’ll store the values of our table in the cell range A4:C4 into an array using the following code:

var events = spreadsheet.getRange(“A4:C4”).getValues();

Step 7

Lastly, we’ll create a for loop that creates a new event for each row in our table.

We can use the following code to perform this:

for (let i = 0; i < events.length; i++) {

e = events[i];

event_Cal.createEvent(e[2], e[0], e[1]);

}

Step 8

After completing our add_events_to_calendar() function, click the Run option to execute the function.

Step 9

The custom Apps Script code should now generate new events based on the provided rows in Google Sheets.

Summary

This guide should be everything you need to create a calendar event from Google Sheets using Apps Script.

You may make a copy of this example spreadsheet to test it out on your own.