如何从 Google 表格将活动添加到 Google 日历

问题描述 投票:0回答:1

我在Google Sheets中创建了一个表格形式,如下:

栏目:

Event Title  | Start Date | Start Time | End Date | End Time | Description | Time Zone

样本记录:

TEST EVENT | 5/23/2024 Thu | 1:00 PM | 5/23/2024,Thu | 3:00 PM | NA | GMT +3

提供 Google Script API 代码示例来解决这个问题就足够了。

google-sheets google-apps-script google-calendar-api
1个回答
0
投票

Google 日历:从 Google 表格添加活动

此示例脚本会检查您的 Google 表格上今天的日期,并向您指定的电子邮件地址发送一封电子邮件。

const myFunction = () => {
  // Gets your current active spreadsheet
  var ss = SpreadsheetApp.getActiveSheet();
  // Gets the calendar of the given ID. Note: Replace "id" with your calendar ID
  var calendarID = CalendarApp.getCalendarById("id");
  // Declares the range to be used and gets its value from the spreadsheet
  var range = ss.getRange("A2:G4").getValues();
  // Loops through the rows and combines Column B with Column C and Column G, as well as Column D with Column E and Column G
  range.forEach(row => {
    var title = row[0];
    var startTime = `${row[1]} ${row[2]} ${row[6]}`;
    var startDate = new Date(startTime);
    var endTime = `${row[3]} ${row[4]} ${row[6]}`;
    var endDate = new Date(endTime);
    var description = row[5];
    // Creates the events with the given title, start date, end date, and description from the spreadsheet
    calendarID.createEvent(title, startDate, endDate, {description: description});
  })
}

https://developers.google.com/apps-script/reference/calendar/calendar-app#getcalendarbyidid

https://developers.google.com/apps-script/reference/calendar/calendar#createeventtitle,-starttime,-endtime,-options

谷歌表格:

输出:

© www.soinside.com 2019 - 2024. All rights reserved.