Skip to content

Instantly share code, notes, and snippets.

@arlogilbert
Last active June 19, 2020 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arlogilbert/9741d0445ebc13c0851a41650a9aab87 to your computer and use it in GitHub Desktop.
Save arlogilbert/9741d0445ebc13c0851a41650a9aab87 to your computer and use it in GitHub Desktop.
Google Calendar to Google Sheets
/*
This is a Google Sheets Script. Create a script on the sheet you want to store your calendar entries in, save it, and set up a trigger.
Set this up as a timed trigger in the morning against a google sheet to have an always up to date list of who you have met with.
For the initial run you may want to set the daysBack to a large number like 999
*/
const me = Session.getActiveUser().getEmail();
const domain = me.substring(me.lastIndexOf("@") +1);
const timeZone = "GMT-6";
const sheetName = "Attendees";
const daysBack = 1;
function Cal2Sheet() {
let beg = new Date(new Date().setDate(new Date().getDate()-daysBack));
beg.setHours(0,0,0,0);
let end = new Date(new Date().setDate(new Date().getDate()-1));
end.setHours(23,59,59,999);
let events = CalendarApp.getDefaultCalendar().getEvents(beg, end);
events.forEach(function(e){
let id = e.getId();
let title = e.getTitle();
let ymd = Utilities.formatDate(e.getStartTime(), timeZone, "yyyy-MM-dd")
if(!e.isRecurringEvent() && !e.isAllDayEvent()){
e.getGuestList(true).forEach(function(g){
if(!g.getEmail().includes(domain)){
AddRow(ymd, id, title, g.getName(), g.getEmail())
}
});
}
});
}
function AddRow(ymd, id, title, name, email) {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(sheetName);
let guestDomain = email.substring(email.lastIndexOf("@") +1);
if(name == ''){
name = 'Unknown';
}
sheet.appendRow([ymd, id, title, email, guestDomain, name]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment