gpt4 book ai didi

javascript - 链接谷歌表格以自动创建日历事件并在更新谷歌表格时更新它们

转载 作者:行者123 更新时间:2023-11-30 21:16:37 26 4
gpt4 key购买 nike

我正在尝试将我的 google 表格链接到日历以自动创建日历事件并在 google 表格中更新时更新它们。我的 google 表格跟踪新建筑开放日期和新建筑施工开始日期,因此我需要它为每一行创建两个适用的日历事件(有时只填写一个日期)。

工作表的标题是“Loc. #”、“Location”、“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;
}

不太确定下一步该怎么做才能实现这一目标。关于如何实现这个有什么建议吗?

最佳答案

您可以尝试查看这些教程和有关如何使用 Google Apps 脚本创建日历事件的问题。这些链接包含一些示例代码,您可以复制这些代码。

有关更多信息或更多想法,您还可以查看本教程,了解如何使用 Google Apps Script in creating a calendar events from Google Form .

关于javascript - 链接谷歌表格以自动创建日历事件并在更新谷歌表格时更新它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45623256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com