用于创建全天日历条目的Google脚本

时间:2015-06-02 00:07:40

标签: google-apps-script

道歉,如果已经涵盖但我正在尝试为谷歌表单编写一个脚本,完成后将发送'事件'到我的谷歌日历。我希望这些活动成为全天活动,但我能做的最接近的工作如下,但我仍然可以在00:00获得时间..有人可以帮忙吗?

///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 = "bj8vckkvvhnq4ujr2sb914n03c@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 = 4;  

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 = "Added by :"+sheet.getRange(lr,descId,1,1).getValue()+"\n"+subOn;  

   var title = sheet.getRange(lr,titleId,1,1).getValue() 

     createEvent(calendarId,title,startDt,endDt,desc);  

 }​  



   function createEvent(calendarId,title,startDt,endDt,desc) {  

   var cal = CalendarApp.getCalendarById(calendarId);  

   var start = new Date(startDt);  

   var end = new Date(endDt);  

   var loc = '';   


   var event = cal.createEvent(title, start, end, {  

       description : desc,  

       location : loc  

   });  

 }; 

1 个答案:

答案 0 :(得分:0)

有一个不同的函数“createAllDayEvent”用于创建全天事件。

https://developers.google.com/apps-script/reference/calendar/calendar#createAllDayEvent(String,Date,Object)