仅在工作日从Google表格创建周期性的Google日历活动 [英] Create recurring Google Calendar events from Google Sheets only on weekdays
问题描述
例如,如果我在2014年9月2日设立了定期会议,未来的会议最终将在周末举行。
这些周期性会议如何才能在平日显示?
例如,如果会议在星期六举行,请将其移至前一天(星期五)的前一天。另一方面,如果会议在星期日举行,则将其移至(星期一)后一天。
是可能的吗?
我尝试过使用CalendarApp.Weekday.MONDAY等...函数,但它最终写入.addMonthlyRule()函数从代码...
//日期|标题|开始时间|结束时间|位置|说明|重复(月)| EventID
函数onOpen(){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name:Export Events,
functionName:exportEvents
}];
sheet.addMenu(日历操作,条目);
};
$ b $ ***将电子表格中的事件导出到日历* /
function exportEvents(){
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 1; //标题信息的行数(跳过)
var range = sheet.getDataRange();
var data = range.getValues();
var calId =airliquide.com_ro3r20vk2rhm506fr2toq4vh5c@group.calendar.google.com;
var cal = CalendarApp.getCalendarById(calId);
for(i in data){
if(i var row = data [i];
var date = new Date(row [0]); //第一列
var title = row [1]; //第二列
var tstart = setTimeToDate(date,row [2]);
var tstop = setTimeToDate(date,row [3]);
Logger.log('date ='+ date +'tstart ='+ tstart +'tstop ='+ tstop);
var loc = row [4];
var desc = row [5];
var times = row [6]
var id = row [7];
//检查事件是否已经存在,如果是,则更新它
try {
var event = cal.getEventSeriesById(id);
event.setTitle('got you'); //如果事件不存在,这就是强制错误,我将永远不会显示真实;-)
} catch(e){
var newEvent = cal.createEvent(title,tstart,tstop,{description:desc,location:loc}); //创建一个正常事件
row [7] = newEvent.getId(); //更新事件ID
的数据数组Logger.log('event created'); //调试
var event = cal.getEventSeriesById(row [7]); //将其设为事件意甲
}
event.setTitle(title);
event.setDescription(desc);
event.setLocation(loc);
var recurrence = CalendarApp.newRecurrence()。addMonthlyRule().interval(times)
//。onlyOnWeekdays(
//[CalendarApp.Weekday.MONDAY,CalendarApp.Weekday.TUESDAY,CalendarApp .Weekday.WEDNESDAY,CalendarApp.Weekday.THURSDAY,CalendarApp.Weekday.FRIDAY]);
event.setRecurrence(recurrence,tstart,tstop); //我们需要保持启动和停止,否则如果仅使用启动,它将成为AllDayEvent
}
range.setValues(data);
函数setTimeToDate(date,time){
var t = new Date(time);
var hour = t.getHours();
var min = t.getMinutes();
var sec = t.getSeconds();
var dateMod = new Date(date.setHours(hour,min,sec,0))
return dateMod;
}
一周通过使用以下内容:
var d = new Date();
var n = d.getDay();
星期日为0,星期一为1等。
The following code below works perfectly. However, I now need to have recurring events to appear only during the weekdays (M-F). If for example I set up a recurring meeting on 9/2/2014, future meetings will eventually fall on a weekend. How can these recurring meetings only show up on weekdays? For example, if meeting falls on a Saturday, move it to the day before (Friday). On the other hand, if meeting falls on a Sunday, move it to the day after (Monday). is this possible?
I have tried using the CalendarApp.Weekday.MONDAY, etc...function but it ends up writing over the .addMonthlyRule() function from the code...
// Date | Title | Start Time | End Time | Location | Description | Recurring (months) | EventID
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Export Events",
functionName : "exportEvents"
}];
sheet.addMenu("Calendar Actions", entries);
};
/*** Export events from spreadsheet to calendar */
function exportEvents() {
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var data = range.getValues();
var calId = "airliquide.com_ro3r20vk2rhm506fr2toq4vh5c@group.calendar.google.com";
var cal = CalendarApp.getCalendarById(calId);
for (i in data) {
if (i < headerRows) continue; // Skip header row(s)
var row = data[i];
var date = new Date(row[0]); // First column
var title = row[1]; // Second column
var tstart = setTimeToDate(date,row[2]);
var tstop = setTimeToDate(date,row[3]);
Logger.log('date = '+date+'tstart = '+tstart+' tstop = '+tstop);
var loc = row[4];
var desc = row[5];
var times = row[6]
var id = row[7];
// Check if event already exists, update it if it does
try {
var event = cal.getEventSeriesById(id);
event.setTitle('got you');// this is to "force error" if the event does not exist, il will never show for real ;-)
}catch(e){
var newEvent = cal.createEvent(title, tstart, tstop, {description:desc,location:loc}); // create a "normal" event
row[7] = newEvent.getId(); // Update the data array with event ID
Logger.log('event created');// while debugging
var event = cal.getEventSeriesById(row[7]);// make it an event Serie
}
event.setTitle(title);
event.setDescription(desc);
event.setLocation(loc);
var recurrence = CalendarApp.newRecurrence().addMonthlyRule().interval(times)
//.onlyOnWeekdays(
//[CalendarApp.Weekday.MONDAY, CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.WEDNESDAY, CalendarApp.Weekday.THURSDAY, CalendarApp.Weekday.FRIDAY]);
event.setRecurrence(recurrence, tstart, tstop);// we need to keep start and stop otherwise it becomes an AllDayEvent if only start is used
}
range.setValues(data);
}
function setTimeToDate(date,time){
var t = new Date(time);
var hour = t.getHours();
var min = t.getMinutes();
var sec = t.getSeconds();
var dateMod = new Date(date.setHours(hour,min,sec,0))
return dateMod;
}
You can get the day of the week by using the following:
var d = new Date();
var n = d.getDay();
Sunday is 0, Monday is 1 etc.
这篇关于仅在工作日从Google表格创建周期性的Google日历活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!