Skip to content

Instantly share code, notes, and snippets.

@ljones140
Last active November 25, 2023 13:59
Show Gist options
  • Save ljones140/aeb743fca4bb7934feb2 to your computer and use it in GitHub Desktop.
Save ljones140/aeb743fca4bb7934feb2 to your computer and use it in GitHub Desktop.
Google Sheets Calender Export

The script below can be used to export your calender dates from google calender to google sheets.

Turns out google sheets allows you to write scripts as .gs files which is basically javascript with some specific features for querying and editing google docs files. Just like the developer mode in Excel but in a nicer language.

Original script I based this on was found here: http://blog.cloudbakers.com/blog/export-google-calendar-entries-to-a-google-spreadsheet. I edited it for my needs.

To use open a new file in google sheets, click on tools > script editor. Paste the code in and put your email address and the date range you want.

Select export_gcal_to_gsheet and click play.

function export_gcal_to_gsheet(){


//your calendar email address here
var mycal = "[email protected]";
var cal = CalendarApp.getCalendarById(mycal);


//put dates here
var events = cal.getEvents(new Date("October 09, 2015 00:00:00 CST"), new Date("October 24, 2015 23:59:59 CST"), {search: '-project123'});


var sheet = SpreadsheetApp.getActiveSheet();

var header = [[ "Week day", "Date", "Event Title", "Event Location" ]]
var range = sheet.getRange(1,1,1,4);
range.setValues(header);

  

for (var i=0;i<events.length;i++) {
  var row=i+2;

  var details=[[ getWeekDay(events[i].getStartTime()),  events[i].getStartTime() , events[i].getTitle() , events[i].getLocation() ]];
  var range=sheet.getRange(row,1,1,4);
  range.setValues(details);
 }
}


function getWeekDay(date){
  var dayNumber = date.getDay();
  var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  return days[dayNumber];
}
@Blueyeitln
Copy link

ljones140,

can you help me with this script? I am trying to change this to give me just the info needed and I can't seem to do it correctly.

Here is what I'm looking for:
Headers: Event Title, Event Location, Event Description, Event Start Date, Event Start Time

Thank you for your help.

@phpnukes
Copy link

phpnukes commented Nov 9, 2023

Managed to get the JavaScript working. Not sure the data is correct. Is there any support for this script with google calendar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment