GoogleAppsScript - getting Calendar event by id - google-apps-script

function getEventById()
{
var cal = CalendarApp.getDefaultCalendar();
var eventseries = cal.getEventSeriesById("0ei62qk010k7m8faua6d0s2pbo#google.com");
Logger.log(eventseries.getTitle());
// how to get event from eventseries
//Logger.log(event.getStartDate());
}
I verified GoogleAppsScirpt for Calendar doc but do not find any way to convert CalendarEventSeries to ClaendarEvent object.
Is there any way to do so ?

I think, currently, there is no such option.
May be you should file a feature request in issue tracker.

This will helps you.
function delete_rec_events()
{
//take care: Date function starts at 0 for the month (January=0)
var fromDate = new Date(2018,0,1,0,0,0); //This is January 1, 2018
var toDate = new Date(2018,0,10,0,0,0); //This is January 10, 2018 at 00h00'00"
var calendarName = '<Name of the Calendar>';
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
var events = calendar.getEvents(fromDate, toDate);
for(var i=0; i<events.length;i++)
{
var ev = events[i];
Logger.log('Checking Event Title === ' + calendar.getEventSeriesById(ev.getId()).getTitle());
calendar.getEventSeriesById(ev.getId()).deleteEventSeries();
Logger.log('Event Deleted');
}
}

Related

Setting cell value with two dates

I'm creating a Google Spreadsheet script with Google App scripts that interacts with Google Calendar. What I'm doing is searching for a specific Calendar event by keyword, pulling the start and end dates from that event, and then the goal is to display those two dates into one spreadsheet cell (mostly for readability sake). In other words, the cell should look like '07/14/19 - 07/20/19.' My code below:
function listEvents() {
var id = "THE ID FOR MY CALENDAR IS HERE";
var cal = CalendarApp.getCalendarById(id);
var startPeriod = new Date();
startPeriod.setHours(0, 0, 0, 0);
var endPeriod = new Date(startPeriod);
endPeriod.setDate(endPeriod.getDate() + 1000);
var sheet = SpreadsheetApp.getActiveSheet();
var gig = sheet.getRange(1,1);
var gigName = gig.getValue(); // get the gig name so you can search for it
var events = cal.getEvents(startPeriod, endPeriod, {search:gigName});
// find the start date of each event in the calendar
var starttime = [];
for (var i = 0; i < events.length; i++) {
starttime.push([events[i].getStartTime()]);
}
// find the end date of each event in the calendar
var endtime = [];
for (var i = 0; i < events.length; i++) {
endtime.push([events[i].getEndTime()]);
var cell = sheet.getRange("E5");
cell.setValue(starttime+endtime);
This is sort of working. I can set starttime in one cell, and endtime in another cell, and they look all nice and pretty ('07/14/19','07/14/19') but when I do cell.setValue(starttime+endtime); the formatting of that cell changes to this messy stuff Sun Jul 14 2019 00:00:00 GMT-0500 (CDT)Sat Jul 20 2019 00:00:00 GMT-0500 (CDT) Just to reiterate, I'd like it to look like '07/14/19-07/20/19.'
I can't tell if this is a code problem or a formatting problem. If anyone can offer some help, it'd be appreciated!
Requirement:
Formatted dates to be concatenated inside .setValue().
Solution:
Format the dates before you concatenate them in your .setValue(). Use the following 3 lines of code to replace the ones currently in your script.
//format the start time
starttime.push([Utilities.formatDate(events[i].getStartTime(), "GMT", "dd/MM/yy")]);
//format the end time
endtime.push([Utilities.formatDate(events[i].getEndTime(), "GMT", "dd/MM/yy")]);
Then your .setValue() should look something like this:
cell.setValue(starttime + ' - ' + endtime);
Example:
function listEvents() {
var id = "THE ID FOR MY CALENDAR IS HERE";
var cal = CalendarApp.getCalendarById(id);
var startPeriod = new Date();
startPeriod.setHours(0, 0, 0, 0);
var endPeriod = new Date(startPeriod);
endPeriod.setDate(endPeriod.getDate() + 1000);
var sheet = SpreadsheetApp.getActiveSheet();
var gig = sheet.getRange(1,1);
var gigName = gig.getValue(); // get the gig name so you can search for it
var events = cal.getEvents(startPeriod, endPeriod, {search:gigName});
// find the start date of each event in the calendar
var starttime = [];
for (var i = 0; i < events.length; i++) {
starttime.push([Utilities.formatDate(events[i].getStartTime(), "GMT", "dd/MM/yy")]);
}
// find the end date of each event in the calendar
var endtime = [];
for (var i = 0; i < events.length; i++) {
endtime.push([Utilities.formatDate(events[i].getEndTime(), "GMT", "dd/MM/yy")]);
}
var cell = sheet.getRange("E5");
cell.setValue(starttime + ' - ' + endtime);
Reference:
Utilities.formatDate
You need to look at the Utilities Service... There is a "Format Date" method there that will allow you to format the date to whatever you want it to look like.

google-apps-script | Delete all events in a month

I am writing a script to delete every event from each of my calendars in a single month. My code:
function myFunction() {
var year = 2018;
var month = 11;
var fromDate = new Date(year,month,1,0,0,0);
var toDate = new Date(year,month,28,0,0,0);
var calendars = ['cal1', 'cal2', 'cal3','cal4','cal5','cal6'];
for (var x = 0; x < calendars.length; x++) {
var calendar = CalendarApp.getCalendarsByName(calendars[x])[0];
var events = calendar.getEvents(fromDate, toDate);
for(var i = 0; i < events.length; i++){
var ev = events[i];
ev.deleteEvent();
}
}
}
When I run my code I get the following error:
TypeError: Cannot call method "getEvents" of undefined. (line 13, file
"Code")
Am I not running getEvents() on a calendar object? Why is this code give me an error when it tries to use that function?
Try this:
I removed the deleteEvents because I don't want to delete my events. But this code produced Calendar Name, Event Title, Event StartTime and Event EndTime for all event in the given period.
function myFunction() {
var year = 2018;
var month = 11;
var fromDate = new Date(year,month,1,0,0,0);
var toDate = new Date(year,month,28,0,0,0);
var calendars = ['You'll have to put your calendar names back in here.']
var html='';
for (var x=0;x<calendars.length;x++) {
var calendar = CalendarApp.getCalendarsByName(calendars[x]);
var events = calendar[0].getEvents(fromDate, toDate);
for(var i = 0; i < events.length; i++){
var ev = events[i];
html+=Utilities.formatString('<br />Calendar Name: %s<br />EventTitle: %s<br />EventStartTime: %s<br />Event End Time: %s',calendar[0].getName(),events[i].getTitle(),events[i].getStartTime(),events[i].getEndTime() );
}
}
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Calendar Events')
}

Google Apps Script getDateCreated, getStartTime, getEndTime all return the date for retrieved calendar event

Trying to write a function to export Google Calendar entries into a Google Sheet. I've created two calendar entries in the date range 2019/02/01 - 2019/03/01 with the text #outreach. The search works and finds the two events I created, and only the two events I created. However, the getStartTime, getEndTime, and getDateCreated functions all return the date/time that I run the function:
function myFunction() {
var defaultCalendar = CalendarApp.getDefaultCalendar();
var lower = new Date(2019, 2, 1);
var upper = new Date(2019, 3, 1);
var events = CalendarApp.getDefaultCalendar().getEvents(lower, upper, {search: '#outreach'});
var startTime = Date(events[1].getStartTime());
Logger.log('Start time: %s', startTime);
var endTime = Date(events[1].getEndTime());
Logger.log('End time: %s', endTime);
var createDate = Date(events[1].getDateCreated());
Logger.log('Create date: %s', createDate);
}
Any ideas as to why?
Some Calendar Events to Spreadsheet
This function also launches a modeless dialog with table of the events found by the search. You'll probably need to change sheet name and search string
function myFunction() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Sheet83');//Sheet Name
var cal = CalendarApp.getDefaultCalendar();
var start = new Date(2019, 0, 1);
var end = new Date(2019, 5, 1);
var events = cal.getEvents(start, end, {search: 'search string'});//search string
sh.appendRow(['Title','Start','End']);
var html='<style>th,td{border:1px solid black;}</style><table><tr><th>Title</th><th>Start Time</th><th>EndTimer</th></tr>';
for(var i=0;i<events.length;i++) {
html+=Utilities.formatString('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', events[i].getTitle(),events[i].getStartTime(),events[i].getEndTime());
sh.appendRow([events[i].getTitle(),events[i].getStartTime(),events[i].getEndTime()])
}
html+='</table>';
var userInterface=HtmlService.createHtmlOutput(html).setWidth(1000);
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Event Information for ' + cal.getName() );
}
Calendar.getEvents()
Comment by https://stackoverflow.com/users/9337071/tehhowch was the solution, i.e., I needed to add the new keyword, as follows
var startTime = new Date(events[1].getStartTime());
Logger.log('Start time: %s', startTime);
var endTime = new Date(events[1].getEndTime());
Logger.log('End time: %s', endTime);
var createDate = new Date(events[1].getDateCreated());
Logger.log('Create date: %s', createDate);

Cannot create an all day event series into google calendar, from google forms

I have been trying for days now, reading other posts, playing with other scripts that have been close to the same purpose and nothing works. I am trying to make a script that will take information from a web based google form, along with a month/day and turn it into a re-occuring event in the Calendar.
It is finally posting to the Calendar NOW but every event comes up undefined under December 31, 2015 - with no further information, altho at least it is reoccurring.
Any help would be greatly appreciated as I try to understand this coding and how to do it. Thank you!
//this is the ID of the calendar to add the event to, this is found on the calendar settings page of the calendar in question
var calendarId = "id#group.calendar.google.com";
//below are the column ids of that represents the values used in the spreadsheet (these are non zero indexed)
var startDtId = 5;
var endDtId = 5;
var titleId = 2;
var descId = 3;
var formTimeStampId = 1;
function getLatestAndSubmitToCalendar() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
var startDt = sheet.getRange(lr,startDtId,1,1).getValue();
//set to first hour and minute of the day.
// startDt.setHours(0);
// startDt.setMinutes(00);
var endDt = sheet.getRange(lr,endDtId,1,1).getValue();
//set endDt to last hour and minute of the day
// endDt.setHours(23);
// endDt.setMinutes(59);
// var subOn = "Submitted on :"+sheet.getRange(lr,formTimeStampId,1,1).getValue();
var desc = sheet.getRange(lr,descId,1,1).getValue();
var title = sheet.getRange(lr,titleId,1,1).getValue();
createAllDayEvent(calendarId,title,startDt,endDt,recurrence,loc,desc);
}​
function createAllDayEventSeries(calendarId,title,startDt,endDt,recurrence,loc,desc) {
var cal = CalendarApp.getCalendarById('id#group.calendar.google.com');
var start = new Date(startDt);
var end = new Date(endDt);
var loc = descId;
var desc = "Happy Birthday "+titleId+" of "+descId;
// Creates a rule that recurs every week for ten weeks.
var recurrence = CalendarApp.newRecurrence().addYearlyRule();
var event = cal.createAllDayEventSeries(title, start, recurrence, {
description : desc,
location : loc
});
};
I created a form and tested with the following code:
// Column data constants
var nameCol = 2;
var birthdayCol = 3;
var descriptionCol = 4;
var locationCol = 4;
var calendarId = '[id]#group.calendar.google.com';
/* Send Confirmation Email with Google Forms */
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("CreateCalendarEvent")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function createEvent() {
var ss = SpreadsheetApp.getActiveSheet();
var rows = ss.getDataRange();
var lr = rows.getLastRow();
var start = ss.getRange(lr,birthdayCol,1,1).getValue();
start.setHours(0);
start.setMinutes(00);
var title = ss.getRange(lr,nameCol,1,1).getValue() + " Birthday";
var desc = ss.getRange(lr,descriptionCol,1,1).getValue();
var loc = ss.getRange(lr,locationCol,1,1).getValue();
var recurrence = CalendarApp.newRecurrence().addYearlyRule();
Logger.log("accessing calendar");
var externalCalendar = CalendarApp.getCalendarById(calendarId);
externalCalendar.createAllDayEventSeries(title, start, recurrence, {
description : desc,
location : loc
});
}
function getRelativeDate(daysOffset, hour) {
var date = new Date();
date.setDate(date.getDate() + daysOffset);
date.setHours(hour);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
return date;
}
function CreateCalendarEvent(e) {
try {
Logger.log("creating event");
createEvent();
} catch (e) {
Logger.log(e.toString());
}
}
This sets a trigger function when the form is submitted, make sure that you change the value of the calendar id to the one provided by your calendar.

google gs multiple calendars events to spreadsheet

attempting to extract all day events from Google calenders (three in total), into three sheadsheet pages each with two set of three column data. Max is about 100 rows in a month takeout. the entries are searchable by name event as well.
help, runs sort of okay, but gives me a time out, which may be to much information, also error pops up with getTitle not found.
anyone with suggestions to improve code and prevent time out, or any other suggestions to tidy up code would be of help. My thanks in advance.
This is what I have so far.
function export_gcal_to_gsheet() {
// This selects events only from calendars in date and list out
// Export Google Calendars Events to a Google Spreadsheet
// This code retrieves events between 2 dates for the specified calendar.
// It logs the results in the current spreadsheet starting at cell A6 listing the events,and date
// I do re-write the spreadsheet header in Row 6 with every run, as I found it faster to delete then entire sheet content,
// 1. Please modify the value for mycal to be YOUR calendar email address or one visible on your MY Calendars section of your Google Calendar
// 2. Please modify the values for events to be the date/time range you want and any search parameters to find or omit calendar entires
// Note: Events can be easily filtered out/deleted once exported from the calendar
// from an original file export_gcal_to_gsheet
// Reference Websites:
// https://developers.google.com/apps-script/reference/calendar/calendar
// https://developers.google.com/apps-script/reference/calendar/calendar-event
var mycal="";
var mySite="canv";
switch (mySite) {
case "canv" : mycal = "*****orqjiaaosl0dt0qp0g#group.calendar.google.com"; break;
case "salf" : mycal = "*****juiigo83ich4iga7sttlpa4#group.calendar.google.com"; break;
case "hart": mycal = "*****qblepqp88utr69vv434s#group.calendar.google.com"; break;
}//end switch
//var mycal = "*****hkdorqjiaaosl0dt0qp0g#group.calendar.google.com";
var cal = CalendarApp.getCalendarById(mycal);
// Optional variations on getEvents
// var events = cal.getEvents(new Date("January 3, 2014 00:00:00 CST"), new Date("January 14, 2014 23:59:59 CST"));
// var events = cal.getEvents(new Date("January 3, 2014 00:00:00 CST"), new Date("January 14, 2014 23:59:59 CST"), {search: 'word1'});
//
// Explanation of how the search section works (as it is NOT quite like most things Google) as part of the getEvents function:
// {search: 'word1'} Search for events with word1
// {search: '-word1'} Search for events without word1
var eventsbell = cal.getEvents(new Date("May 1, 2014 00:00:00 GMT"), new Date("May 10, 2014 23:59:59 GMT"), {search: 'bell'});
var eventspers = cal.getEvents(new Date("May 1, 2014 00:00:00 GMT"), new Date("May 2, 2014 23:59:59 GMT"), {search: 'pers'});
//var sheet = SpreadsheetApp.getActiveSheet();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(mySite);
// Uncomment this next line if you want to always clear the spreadsheet content before running - Note people could have added extra columns on the data though that would be lost
sheet.clearContents();
// Create a header record on the current spreadsheet in cells A5:C5,E5:G5 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below
var header = [["Delivery Branch test", "Customer and Site test", "Delivery Date test"]]
var rangebell = sheet.getRange(5,1,1,3);
rangebell.setValues(header);
var rangepers = sheet.getRange(5,5,1,3);
rangepers.setValues(header);
// Loop through all calendar events found and write them out starting on calculated ROW 6 (i+6)
for (var i=0;i<eventsbell.length;i++) {
var row=i+6;
for (var i=0;i<eventspers.length;i++) {
var row=i+6;
// Matching the "header=" entry above, this is the detailed row entry "details=", and must match the number of entries of the GetRange entry below
var detailsbell = [[ mycal,eventsbell[i].getTitle(),eventsbell[i].getStartTime()]];
var rangebell = sheet.getRange(row,1,1,3);
rangebell.setValues(detailsbell);
var detailspers = [[ mycal,eventspers[i].getTitle(),eventspers[i].getStartTime()]];
var rangepers = sheet.getRange(row,5,1,3);
rangepers.setValues(detailspers);
}
}
}
I wrote such a script some time ago and use it all the time without issues. Here is a simplified version of it that you could try to see if it eventually works for you.
The code is a bit long but the operation is all but simple so I guess there is probably no way to make it really shorter.
I know that some methods used in this code are being deprecated (getTimeZone for example) but it will be easy to update when they become unavailable... for now it works as it is, I'll update when I get some time to do it.
Here is the link to a test sheet (in view only, make a copy to use)
var FUS1=new Date().toString().substr(25,6)+":00";
var tz = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone();
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{name: "ImportCalendars", functionName: "Cal_to_sheetM"},
];
ss.addMenu("import cals", menuEntries);
}
function Cal_to_sheetM() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle("Import Calendars");
app.setHeight(365).setWidth(600);
// Create a grid with 3 text boxes and corresponding labels
var grid = app.createGrid(6, 2);
var wait = app.createImage('https://dl.dropboxusercontent.com/u/211279/loading3.gif').setVisible(false);
grid.setWidget(0, 0, app.createLabel("Cal Names :"));
var list = app.createListBox(true).setVisibleItemCount(5);
list.setName('calendar');
grid.setWidget(0, 1, list);
var calendars = CalendarApp.getAllCalendars();
for (var i = 0; i < calendars .length; i++) {
list.addItem(calendars[i].getName());
}
list.setItemSelected(0, true);
grid.setWidget(1, 0, app.createCheckBox("add cal Name to events").setName('addName').setValue(false))
.setWidget(2, 0, app.createLabel('start Date :'))
.setWidget(2, 1, app.createDateBox().setId("start").setValue(new Date(PropertiesService.getScriptProperties().getProperty('startDate'))))
.setWidget(3, 0, app.createLabel('End Date :'))
.setWidget(3, 1, app.createDateBox().setId("end").setValue(new Date(PropertiesService.getScriptProperties().getProperty('endDate'))))
.setWidget(4,0, app.createCheckBox("create new sheet").setName('newsheet').setValue(false));
var panel = app.createVerticalPanel();
panel.add(grid);
var button = app.createButton('Import');
var handler = app.createServerClickHandler('importEventsMulti');
handler.addCallbackElement(grid);
var cHandler = app.createClientHandler().forTargets(wait).setVisible(true).forEventSource().setEnabled(false);
button.addClickHandler(handler).addClickHandler(cHandler);
grid.setWidget(5, 1,button).setWidget(4,1, wait);
app.add(panel.add(grid));
doc.show(app);
}
function importEventsMulti(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var calendar_name = e.parameter.calendar.split(',');
var addName = e.parameter.addName=='true';
var newsheet = e.parameter.newsheet=='true';
var empty = ''
var startDate = new Date(e.parameter.start);
var endDate = new Date(e.parameter.end);
var sheetName = calendar_name.join('&');
if(newsheet){
try{
var sheet = ss.insertSheet(sheetName,0);
}catch(error){
FUS1=new Date().toString().substr(25,6)+":00";
var sheet = ss.insertSheet(sheetName+'-'+Utilities.formatDate(new Date(), FUS1, "HH:mm:ss"),0);
}
}else{
var allSheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var sheetNames = '';
for(var s in allSheets){sheetNames+=allSheets[s].getName()};
if(sheetNames.indexOf(sheetName)>-1){
var newsheetName = sheetName+'-'+Utilities.formatDate(new Date(), FUS1, "HH:mm:ss")
}else{
var newsheetName = sheetName
}
var sheet = ss.getActiveSheet().setName(newsheetName);
}
var eventArray = new Array();
for(n=0;n<calendar_name.length;++n){
//Logger.log(calendar_name[n])
var Calendar = CalendarApp.getCalendarsByName(calendar_name[n]);
var events = Calendar[0].getEvents(startDate , endDate, {max: 4000});
if (events[0]){
for (i = 0; i < events.length; i++) {
var line = new Array();
FUS1=events[i].getStartTime().toString().substr(25,6)+":00";
var title = events[i].getTitle()
if(addName){title+=(' ('+calendar_name[n]+')')}
line.push(title);
line.push(Utilities.formatDate(events[i].getStartTime(), FUS1, "dd-MM-yyyy")+' # ' +Utilities.formatDate(events[i].getStartTime(), FUS1, "HH:mm"));
line.push(Utilities.formatDate(events[i].getEndTime(), FUS1, "dd-MM-yyyy")+' # ' +Utilities.formatDate(events[i].getEndTime(), FUS1, "HH:mm"));
line.push(events[i].getLocation());
line.push(' -- ')
line.push(((events[i].getEndTime() - events[i].getStartTime())/ 3600000).toString().replace('.',','));
line.push(' ')
eventArray.push(line);
}
}else {
var startstring = Utilities.formatDate(e.parameter.start, FUS1, "dd-MM-yyyy");
var endstring = Utilities.formatDate(e.parameter.end, FUS1, "dd-MM-yyyy");
empty += calendar_name[n]+' - ';
}
}
if(empty.length>1){
Browser.msgBox('No events between ' + startstring + ' and ' + endstring +' in these calendars :'+empty);
}
//Logger.log(eventArray)
eventArray.sort(function(x,y){
var xp = new Date(x[1].substr(6,4)+'/'+x[1].substr(3,2)+'/'+x[1].substr(0,2)+' '+x[1].substr(13,2)+':'+x[1].substr(16,2)+':00').getTime();
var yp = new Date(y[1].substr(6,4)+'/'+y[1].substr(3,2)+'/'+y[1].substr(0,2)+' '+y[1].substr(13,2)+':'+y[1].substr(16,2)+':00').getTime();
return xp == yp ? 0 : xp > yp ? 1 : -1;
});
// now check for any double entry starting from the end
var eventArrayN = [];
var doublons = [];
for(i in eventArray){
var row = eventArray[i];
var duplicate = false;
for(j in eventArrayN){
if(row.join() == eventArrayN[j].join()){
duplicate = true;
}
}
if(!duplicate){
eventArrayN.push(row);
}else{
doublons.push(row);
}
}
var titre = ['calendars '+calendar_name.join(' + '),'starting ','ending','Ressources','--','duration','totals'];
eventArrayN.unshift(titre);
//Logger.log(eventArrayN.length);
// ss.setActiveSheet(ss.getSheets()[1]);
var lastRow = sheet.getLastRow();
sheet.getDataRange().clearContent().setBorder(false,false,false,false,false,false).setBackgroundColor('#ffffff')
sheet.getRange(1,1,eventArrayN.length,eventArrayN[0].length).setValues(eventArrayN);
sheet.setColumnWidth(1, 450).setColumnWidth(2, 150).setColumnWidth(3, 150).setColumnWidth(4, 250).setColumnWidth(5, 120).setColumnWidth(6, 75).setColumnWidth(7, 450);;
sheet.setFrozenRows(1)
sheet.getRange(1,1,1,eventArrayN[0].length).setBorder(true,true,true,true,true,true).setBackgroundColor('#cccccc').setFontWeight('bold').setHorizontalAlignment('center');
sheet.getRange('G' + (eventArrayN.length+1)).setValue('Total (global)').setBorder(true,true,true,true,true,true).setBackgroundColor('#cccccc');
sheet.getRange('F' + (eventArrayN.length+1)).setFormula('=SUM(F2:F' + (eventArrayN.length)+ ')').setBorder(true,true,true,true,true,true).setBackgroundColor('#cccccc');
var max = sheet.getMaxColumns();
var cstart = sheet.getLastColumn();
var n ;
for(n=max;n>cstart;--n){sheet.deleteColumn(n)}
var app = UiApp.getActiveApplication();
app.close();
if(doublons.length>0){
Browser.msgBox("There are duplicates in "+sheetName+", see log sheet");
var sheet = ss.insertSheet('LOG-'+Utilities.formatDate(new Date(), FUS1, "HH:mm:ss"),1);
Utilities.sleep(1500);
var titre = ['calendar : '+calendar_name.join(' + '),'start ','end','Ressources','--','Duration',' comments '];
doublons.unshift(titre);
sheet.getRange(1,1,doublons.length,doublons[0].length).setValues(doublons)
sheet.setColumnWidth(1, 450).setColumnWidth(2, 150).setColumnWidth(3, 150).setColumnWidth(4, 250).setColumnWidth(5, 120).setColumnWidth(6, 75).setColumnWidth(7, 450);;
sheet.setFrozenRows(1)
sheet.getRange(1,1,1,eventArrayN[0].length).setBorder(true,true,true,true,true,true).setBackgroundColor('#cccccc').setFontWeight('bold').setHorizontalAlignment('center');
sheet.getRange('G' + (eventArrayN.length+1)).setValue('Total global').setBorder(true,true,true,true,true,true).setBackgroundColor('#cccccc');
sheet.getRange('F' + (eventArrayN.length+1)).setFormula('=SUM(F2:F' + (eventArrayN.length)+ ')').setBorder(true,true,true,true,true,true).setBackgroundColor('#cccccc');
var max = sheet.getMaxColumns();
var cstart = sheet.getLastColumn();
var n ;
for(n=max;n>cstart;--n){sheet.deleteColumn(n)}
}
PropertiesService.getScriptProperties().setProperty('startDate',startDate);
PropertiesService.getScriptProperties().setProperty('endDate',endDate);
return app;
}