我在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 表格上今天的日期,并向您指定的电子邮件地址发送一封电子邮件。
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