Skip to content

Task guide

Export Calendar events to a Google Sheet

Read events from your Google Calendar for a chosen number of upcoming days and write their titles, times, locations, and guest counts to a Google Sheet tab.

1 · Prepare

Put these pieces in place

  • Create a Sheet tab named Calendar Export (the script overwrites its contents each time it runs).
  • Sign in as the account whose Google Calendar you want to export.
  • Keep the date window short (such as 30 days) so the export finishes well inside the 6-minute limit.

Change these values

Change these values

Make the code yours before you run it.
Sheet name
Calendar Export

Existing tab that will be cleared and refilled.

Days ahead
30

Number of days starting from today to include.

2 · Review before running

What the script can access and change

Permissions you approve

  • See, edit, share, and permanently delete all the calendars you can access using Google Calendar. The code only reads events from your default calendar.
  • See, edit, create, and delete all your Google Sheets spreadsheets. The code clears and rewrites only the Calendar Export tab.

Effects of one run

  • Clears all existing values on the Calendar Export tab and writes one header row plus one row per event in the chosen date window.
  • Leaves your Google Calendar and every other Sheet tab unchanged.

3 · Copy

Paste this into the Apps Script editor

Create or open a script file, replace the example values marked above, then save the project.

Code.gs
const SHEET_NAME = 'Calendar Export'; // Existing tab that will be cleared and refilled.
const DAYS_AHEAD = 30; // Number of days starting from today to include.

function exportCalendarEventsToSheet() {
  const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = spreadsheet.getSheetByName(SHEET_NAME);
  if (!sheet) {
    throw new Error('Add a Sheet tab named ' + SHEET_NAME + ' before running this function.');
  }

  const timeZone = spreadsheet.getSpreadsheetTimeZone();
  const startDate = new Date();
  startDate.setHours(0, 0, 0, 0);
  const endDate = new Date(startDate.getTime() + DAYS_AHEAD * 24 * 60 * 60 * 1000);

  const calendar = CalendarApp.getDefaultCalendar();
  const events = calendar.getEvents(startDate, endDate);

  const rows = [['Title', 'Start', 'End', 'All day', 'Location', 'Guests', 'Event ID']];
  events.forEach((event) => {
    const title = event.getTitle();
    const location = event.getLocation();
    rows.push([
      /^[=+@-]/.test(title) ? "'" + title : title,
      Utilities.formatDate(event.getStartTime(), timeZone, 'yyyy-MM-dd HH:mm'),
      Utilities.formatDate(event.getEndTime(), timeZone, 'yyyy-MM-dd HH:mm'),
      event.isAllDayEvent() ? 'Yes' : 'No',
      /^[=+@-]/.test(location) ? "'" + location : location,
      String(event.getGuestList().length),
      event.getId(),
    ]);
  });

  sheet.clearContents();
  sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
  Logger.log('Exported ' + events.length + ' calendar events to ' + SHEET_NAME + '.');
}

4 · Run

Follow these steps in order

  1. Create the output tab

    Add a blank tab named Calendar Export to your Google Sheet so existing data on other tabs is untouched.

  2. Paste the script and save

    Choose Extensions, then Apps Script, replace the starter function with this code, and press Ctrl+S or Cmd+S.

  3. Run once and approve access

    Select exportCalendarEventsToSheet in the dropdown beside Run, click Run, and approve access to Google Calendar and Google Sheets.

  4. Review the exported table

    Switch back to the Calendar Export tab and verify the headers and event rows. Adjust DAYS_AHEAD or swap getDefaultCalendar() for CalendarApp.getCalendarById() if you need a shared calendar.

5 · Confirm

How to tell it worked

The Calendar Export tab shows one row per upcoming event with formatted start and end times, location, guest count, and event ID.

If the result is different

Troubleshooting

The exported times are shifted by several hours.
Open File, then Settings in Google Sheets and check the spreadsheet Time zone. The script formats timestamps using the spreadsheet time zone.
Shared calendar events do not appear.
getDefaultCalendar() reads only your primary calendar. Replace it with CalendarApp.getCalendarById("your-calendar-id") using the ID from Google Calendar settings.

Technical details

Names used in this script

Open these details when you want to adapt the example or look up an exact service or method name.

Show Apps Script symbols and service pages

Keep going