Javascript 链接google工作表以自动创建日历事件,并在google工作表更新时进行更新
我正在尝试将我的google工作表链接到日历,以自动创建日历事件,并在google工作表中更新时进行更新。我的google工作表跟踪新建筑的开放日期和新建筑的开工日期,因此对于每一行,我需要它在适用时创建两个日历事件(有时只填写了其中一个日期) 工作表的标题为“位置”、“位置”、“Cons Start”和“Whse Open” 每个标题的值都是从对不同工作表的引用中填充的,并且由于是引用,因此会从该工作表自动更新 我不太喜欢javascript,但到目前为止,我为google apps脚本编写的代码如下:Javascript 链接google工作表以自动创建日历事件,并在google工作表更新时进行更新,javascript,google-apps-script,google-sheets,google-calendar-api,Javascript,Google Apps Script,Google Sheets,Google Calendar Api,我正在尝试将我的google工作表链接到日历,以自动创建日历事件,并在google工作表中更新时进行更新。我的google工作表跟踪新建筑的开放日期和新建筑的开工日期,因此对于每一行,我需要它在适用时创建两个日历事件(有时只填写了其中一个日期) 工作表的标题为“位置”、“位置”、“Cons Start”和“Whse Open” 每个标题的值都是从对不同工作表的引用中填充的,并且由于是引用,因此会从该工作表自动更新 我不太喜欢javascript,但到目前为止,我为google apps脚本编写的
// Calendar ID can be found in the "Calendar Address" section of the Calendar Settings.
var calendarId = 'costco.com_19rlkujqr1v5rfvjjj8p1g8n8c@group.calendar.google.com';
// Configure the year range you want to synchronize, e.g.: [2006, 2017]
var years = [2017,2020];
// Date format to use in the spreadsheet.
var dateFormat = 'M/d/yyyy H:mm';
var titleRowMap = {
'loc#': 'Loc. #',
'location': 'Location',
'conStart': 'Cons Start',
'whseOpen': 'Whse Open',
};
var titleRowKeys = ['loc#', 'location', 'conStart', 'WhseOpen'];
var requiredFields = ['loc#', 'location', 'conStart', 'WhseOpen'];
// This controls whether email invites are sent to guests when the event is created in the
// calendar. Note that any changes to the event will cause email invites to be resent.
var SEND_EMAIL_INVITES = false;
// Setting this to true will silently skip rows that have a blank start and end time
// instead of popping up an error dialog.
var SKIP_BLANK_ROWS = false;
// Updating too many events in a short time period triggers an error. These values
// were tested for updating 40 events. Modify these values if you're still seeing errors.
var THROTTLE_THRESHOLD = 10;
var THROTTLE_SLEEP_TIME = 75;
// Adds the custom menu to the active spreadsheet.
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{
name: "Update from Calendar",
functionName: "syncFromCalendar"
}, {
name: "Update to Calendar",
functionName: "syncToCalendar"
}
];
spreadsheet.addMenu('Calendar Sync', menuEntries);
}
// Creates a mapping array between spreadsheet column and event field name
function createIdxMap(row) {
var idxMap = [];
for (var idx = 0; idx < row.length; idx++) {
var fieldFromHdr = row[idx];
for (var titleKey in titleRowMap) {
if (titleRowMap[titleKey] == fieldFromHdr) {
idxMap.push(titleKey);
break;
}
}
if (idxMap.length <= idx) {
// Header field not in map, so add null
idxMap.push(null);
}
}
return idxMap;
}
// Converts a spreadsheet row into an object containing event-related fields
function reformatEvent(row, idxMap, keysToAdd) {
var reformatted = row.reduce(function(event, value, idx) {
if (idxMap[idx] != null) {
event[idxMap[idx]] = value;
}
return event;
}, {});
for (var k in keysToAdd) {
reformatted[keysToAdd[k]] = '';
}
return reformatted;
}
//可以在日历设置的“日历地址”部分找到日历ID。
var calendarId='costco.com_19rlkujqr1v5rfvjjj8p1g8n8c@group.calendar.google.com';
//配置要同步的年份范围,例如:[2006、2017]
风险值年数=[20172020];
//要在电子表格中使用的日期格式。
var dateFormat='M/d/yyyy H:mm';
变量titleRowMap={
‘loc#’:‘loc.#’,
“位置”:“位置”,
“康斯塔特”:“犯人开始”,
“whseOpen”:“Whse Open”,
};
变量titleRowKeys=['loc#','location','conStart','WhseOpen'];
var requiredFields=['loc#','location','conStart','WhseOpen'];
//此选项控制在中创建活动时是否向来宾发送电子邮件邀请
//日历。请注意,对活动的任何更改都将导致重新发送电子邮件邀请。
var SEND_EMAIL_invests=false;
//将此设置为true将自动跳过起始和结束时间为空的行
//而不是弹出一个错误对话框。
var SKIP_BLANK_ROWS=false;
//在短时间内更新太多事件会触发错误。这些价值观
//我们测试了40个事件的更新。如果仍看到错误,请修改这些值。
无功功率阈值=10;
var节流阀睡眠时间=75;
//将自定义菜单添加到激活的电子表格中。
函数onOpen(){
var电子表格=SpreadsheetApp.getActiveSpreadsheet();
变量菜单项=[
{
名称:“从日历更新”,
函数名:“syncFromCalendar”
}, {
名称:“日历更新”,
函数名:“syncToCalendar”
}
];
电子表格.addMenu('日历同步',菜单项);
}
//在电子表格列和事件字段名称之间创建映射数组
函数createIdxMap(行){
var idxMap=[];
对于(var idx=0;idx 如果(idxMap.length,您可以尝试查看这些教程以及有关如何使用Google Apps脚本创建日历事件的问题。这些链接包括一些示例代码,您可以从下面的示例代码中复制
有关更多信息或想法,您还可以查看本教程,了解如何使用