Skip to content

Instantly share code, notes, and snippets.

@cadu-leite
Created December 8, 2019 14:42
Show Gist options
  • Save cadu-leite/b093922e46b0d6524a70bc448952ab1c to your computer and use it in GitHub Desktop.
Save cadu-leite/b093922e46b0d6524a70bc448952ab1c to your computer and use it in GitHub Desktop.
Script transfere eventos do google Sheet para Google Calendar
// formato da planilha
// Colunas
//Moderadores | dia inicio | duracao | titulo | palestrante | link | mail | data_inicio | data_fim | calendar.object.id
// conteudo a partir da linha 10 ou altere alinha
// ... var slots = sps.getRange("agenda-calendario!A10:K"+last_row+"").getValues();
// para
// ... var slots = sps.getRange("<NOME_SHEET>!A10:K"+last_row+"").getValues();
function slots_2_calendar() {
var sps = SpreadsheetApp.getActiveSheet();
// URL publica do calendario https://calendar.google.com/calendar/embed?src=8r072qcict1g5skcf4p2ei9n0c%40group.calendar.google.com&ctz=America%2FSao_Paulo
var eventCal = CalendarApp.getCalendarById("<ID_DO_CALENDARIO_VER_EM_FONFIGURACOES>");
var last_row = sps.getLastRow();
var slots = sps.getRange("agenda-calendario!A10:K"+last_row+"").getValues();
for (var x=0; x<slots.length;x++){
var cols = slots[x];
var inicio = cols[8];
// se existe horario
if (typeof inicio!='undefined' && inicio !='' ){
var fim = cols[9];
var palestrante= cols[5];
var titulo= cols[4];
var link = cols[6];
var event_id = cols[10];
var descricao = {
'description': titulo + '\n palestrante:' + palestrante + '\n ' + 'moderador(es):' + cols[0] ,
};
console.log(inicio);
evento = eventCal.getEventById(event_id);
if (evento!='' && evento!=null){
try{
evento.deleteEvent();
}
catch(e){
console.log(e);
}
}
evento=eventCal.createEvent("#PyJamas:" + titulo + " ("+ palestrante +")", inicio, fim , descricao);
//console.log(evento);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment