Google Sheets to Google Calendar Script Guide
In this article
You can sync Google Sheets to Google Calendar by using Google Apps Script, a JavaScript-based platform that allows you to automate tasks across Google Workspace. This process involves writing a script that reads specific cells (event name, start date, end date) and uses the CalendarApp service to create corresponding events in your calendar automatically. This eliminates the need for manual data entry and ensures your schedule stays aligned with your project trackers or event lists.
What You'll Need
- A Google Account with access to both Google Sheets and Google Calendar.
- A Google Sheet formatted with specific columns for event details (Title, Start Date, End Date).
- Basic familiarity with copying and pasting code into a script editor.
- The Calendar ID of the specific calendar you wish to populate (usually your email address for the primary calendar).
Step-by-Step
- Prepare Your Spreadsheet: Open a new or existing Google Sheet. You must organize your data in a consistent table format so the script knows where to look. Create headers in the first row. For example: Column A: Event Name, Column B: Start Date, Column C: End Date, Column D: Description. Ensure your date columns are formatted as "Date" via the Format > Number > Date menu. If the dates are entered as plain text, the script may fail to recognize them as valid timestamps.
- Open the Apps Script Editor: In your Google Sheet, click on the Extensions menu and select Apps Script. This will open a new browser tab with the Google Apps Script editor. Note that menu labels may differ slightly depending on your account version or region.
- Clear the Default Code: You will see a default function called
myFunction(). Delete all existing code in the editor window to ensure there are no conflicts with the new script. - Insert the Automation Script: Copy and paste the following code into the editor:
function createCalendarEvents() { var sheet = SpreadsheetApp.getActiveSheet(); var calendarId = 'primary'; // Use 'primary' or your specific email address var eventCal = CalendarApp.getCalendarById(calendarId); // Get the data range starting from row 2 to skip headers var data = sheet.getRange(2, 1, sheet.getLastRow() - 1, 4).getValues(); for (var i = 0; i < data.length; i++) { var row = data[i]; var title = row[0]; var startTime = new Date(row[1]); var endTime = new Date(row[2]); var description = row[3]; // Only create event if title and start time exist if (title !== "" && !isNaN(startTime.getTime())) { eventCal.createEvent(title, startTime, endTime, { description: description }); } } SpreadsheetApp.getUi().alert('Events successfully added to your calendar!'); } - Save the Project: Click the disk icon (Save project) in the toolbar. Give your project a name, such as "Sheets to Calendar Sync," and click OK.
- Authorize the Script: Click the Run button (the play icon) at the top of the editor. Because this script accesses your private calendar and spreadsheet data, Google will prompt you for permissions. Click "Review Permissions," choose your Google account, and click "Allow." If you see a warning stating "Google hasn't verified this app," click "Advanced" and then click "Go to Sheets to Calendar Sync (unsafe)" to proceed. This is normal for scripts you write yourself.
- Verify the Results: Once the script finishes running, you will see the alert "Events successfully added to your calendar!" Open your Google Calendar to verify that the events from your sheet now appear on the correct dates.
- Optional: Create a Custom Menu: To avoid opening the script editor every time you want to sync, you can add a custom button to your sheet. Add this code below the previous function:
After adding this, refresh your Google Sheet. A new menu called "Calendar Sync" will appear next to "Help," allowing you to run the script with one click.function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Calendar Sync') .addItem('Sync Now', 'createCalendarEvents') .addToUi(); }
Common Mistakes
One of the most frequent errors is incorrect date formatting. If a cell contains "October 12th" instead of "2023-10-12" or a standard date format, the new Date() constructor in JavaScript may return an "Invalid Date" error, causing the script to skip that row or crash. Always ensure your date columns are strictly formatted as dates using the Google Sheets formatting tools.
Another common mistake is running the script multiple times without clearing the calendar. The script provided is a simple "append" script; it does not check if an event already exists. If you run the script five times, you will have five duplicate entries for every row in your spreadsheet. To avoid this, you should either clear your calendar manually before running the script or add a "Status" column in your sheet (e.g., Column E) that the script marks as "Synced" after processing, and then modify the code to skip rows already marked as synced.
Users also frequently forget to specify the correct Calendar ID. While "primary" works for the main calendar associated with the account, if you are pushing events to a shared team calendar or a secondary calendar, you must find the Calendar ID in the calendar's settings (under "Integrate calendar") and paste that long string of characters into the calendarId variable.
Tips
To make your workflow more efficient, consider using a "Sync" checkbox. You can add a checkbox in the final column of your data. By modifying the script to only process rows where the checkbox is "False," you can select exactly which new events to push to the calendar without affecting existing ones. Once the event is created, the script can automatically check the box to "True."
For events that occur all day, the createEvent method might not be the best choice. Instead, use createAllDayEvent(title, date, options). This ensures the event appears in the top bar of the calendar rather than occupying a specific time slot, which is ideal for deadlines or holidays.
If you have a very large dataset (hundreds of rows), the script may hit the Google Apps Script execution time limit. To prevent this, process your data in smaller batches or use a trigger to run the script incrementally. You can set up a "Time-driven trigger" by clicking the clock icon (Triggers) in the Apps Script sidebar, allowing the sheet to sync automatically every hour or every day without any manual intervention.
Troubleshooting
If the script does not run or throws an error, first check the "Execution Log" at the bottom of the Apps Script editor. This log provides specific error messages. If you see a "Permission Denied" error, it means the script lacks the necessary scopes to access your calendar. Try deleting the script project and recreating it, ensuring you accept all permission prompts during the first run.
If the script runs but no events appear in the calendar, verify that you are looking at the correct calendar. If you used a specific Calendar ID, ensure that ID is exactly correct and that your account has "Make changes to events" permissions for that specific calendar. If you used "primary," ensure you are logged into the same Google account for both the Sheet and the Calendar.
If you encounter a "Range not found" or "Cannot read property 'getValues' of null" error, check your spreadsheet structure. This usually happens if the script is looking for a sheet that has been renamed or if the getLastRow() function is returning 0 because the sheet is empty. Ensure there is at least one row of data below your headers.
If the dates are appearing in the wrong time zone, check both the Google Sheet settings (File > Settings > Time zone) and the Google Calendar settings. If these two do not match, the script may shift your events by several hours. Align both to the same time zone to ensure accuracy.
Frequently Asked Questions
Can I sync events from a shared sheet to a shared calendar?
Yes, as long as the account running the script has "Editor" or "Owner" permissions on both the Google Sheet and the target Google Calendar. The script operates under the authority of the user who executes it.
Will changes made in the Sheet automatically update the Calendar?
No, the basic script provided is a one-way push. If you change a date in the Sheet, you must run the script again. However, this will create a duplicate event unless you manually delete the old one or write a more complex script that searches for existing event IDs.
Is there a limit to how many events I can add?
Google imposes daily quotas on the number of calendar events created via API. While these limits are generous for individual users, attempting to add thousands of events in a single execution may trigger a quota limit error.
Can I add event colors or reminders via the script?
Yes, the createEvent method allows for additional options. While basic colors are limited, you can use the setColor() method on the event object returned by createEvent to change the event's appearance.
Do I need to be a coder to use this?
No. While the script is written in JavaScript, you only need to copy and paste the code into the editor and follow the authorization steps to make it work.