function ExportCal() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh1 = ss.getSheetByName('Сервис');
var data = sh1.getDataRange().getValues();
var calname = CalendarApp.getCalendarsByName("ГАРДБОКС-ББЛ Сервис и монтажи");
if (calname.length > 0)
{
var currentCalendar = calname[0];
}
else
{
var currentCalendar = CalendarApp.createCalendar("ГАРДБОКС-ББЛ Сервис и монтажи");
}
var events = currentCalendar.getEvents(new Date(2010,01,01),new Date(2030,01,01));
for (var j = 0 ; j < events.length; j++)
{
events[j].deleteEvent();
}
for (var i = 1; i < data.length; i++)
{
var Data = new Date(data[i][9]);
var now = new Date().getMonth();
var month = now+1;
if ((Data.getMonth()<=month)&&(Data.getMonth()>=month-1)){
var Name = data[i][3];
var Phone = data [i][4];
var desc = data [i][6];
var loc = data [i][5];
var event = currentCalendar.createEvent(""+Name+" . \n"+""+Phone,Data,new Date(Data.getTime()+1*60*60*1000), {description:desc, location:loc});
event.addEmailReminder(0);
event.addPopupReminder(0)
}
}
}