Google日历与Google电子表格同步

Kas*_*und -2 google-calendar-api google-sheets google-apps-script

我发现了这个非常棒的脚本,可以同步Google Cal和Google电子表格。双向同步。而且有效!-> https://github.com/Davepar/gcalendarsync

现在,我无法将日历的地址放在名为Data的工作表中。在单元格B1中。脚本应该从那里拉地址,这样我就不需要在脚本中更改它。

有人可以弄清楚该怎么做吗?
更改将涉及通过Data!B1来定义calendarId
并且脚本应仅在工作表上运行

您可以在此处查看示例文档:https : //docs.google.com/spreadsheets/d/1TCIIBRmshx2kmhhwrhCpg5sxO7N82tOJ7hHxWv_u-Yw/edit? usp =sharing

我在工作表脚本上复制了脚本

Ted*_*noz 5

日历ID在第8行声明

var calendarId = 'bora-bora.dk_is0cr9ibe4thrs4mkqghvudrrk@group.calendar.google.com';
Run Code Online (Sandbox Code Playgroud)

它由两个函数调用:
1 = syncFromCalendar第223行。从日历同步到电子表格。

var calendar = CalendarApp.getCalendarById(calendarId);
Run Code Online (Sandbox Code Playgroud)

2 = syncToCalendar在307行。从电子表格同步到日历。

var calendar = CalendarApp.getCalendarById(calendarId);
Run Code Online (Sandbox Code Playgroud)

目的是通过编程方式调用日历ID,以从数据表的单元格B1中获取值。
为此,i)应当删除变量,ii)添加/插入新代码以获取日历ID的新值,并且iii)对要求日历ID值的函数进行调整。

行动:

1-注释掉第8行
2-在第9行中插入以下代码

// Get the calendar code from Sheet "Data", cell B1
function getcalendarId() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName("Data");
  var calrange = sheet.getRange("B1");
  var calid =calrange.getValue();
  return calid;
}
Run Code Online (Sandbox Code Playgroud)

3-找到函数= syncFromCalendar
3.1-注释掉该行

var calendar = CalendarApp.getCalendarById(calendarId);
Run Code Online (Sandbox Code Playgroud)

3.2在注释行上方插入/添加这三行

// Get the calendar ID
var calidFrom = getcalendarId();
var calendar = CalendarApp.getCalendarById(calidFrom);
Run Code Online (Sandbox Code Playgroud)

4-查找功能= syncToCalendar
4.1注释掉这一行

var calendar = CalendarApp.getCalendarById(calendarId);
Run Code Online (Sandbox Code Playgroud)

4.2在注释行上方插入/添加这三行

// Get the calendar ID
var calidTo = getcalendarId();
var calendar = CalendarApp.getCalendarById(calidTo);
Run Code Online (Sandbox Code Playgroud)

  • 答案可能会被拒绝的原因很多。但是,成为第一个否决票却不评论原因的人是无益的。答案是否错误,是否完整,是否未回答问题等等?这个问题坐了一个月,没有任何回应。我既不是圣人也不是烈士,但如果我们要尝试帮助提问者,那么投票否决者有义务至少对答案的哪些方面激发了他们的投票发表评论。 (2认同)