我正在尝试创建一个 Google Apps 脚本,以使 Google 日历和云端硬盘上的“主电子表格”保持同步——这可能吗?我找到了这两个帖子:
http://blog.ouseful.info/2010/03/04/maintaining-google-calendars-from-a-google-spreadsheet/
http://blog.ouseful.info/2010/03/05/grabbing-google-calendar-event-details-into-a-spreadsheet/
我很确定这可以使用大量 if 语句和逻辑来完成,但也许有更简单的方法?
我最终只提供了以下简单的脚本。真正需要的只是添加基于两列的事件,而这将花费太长时间来开发。
function onOpen() {
//spawns a menu with a button that triggers AddToCal
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Add event to calendar",
functionName : "AddToCal"
}];
sheet.addMenu("Data To Calendar Plugin", entries);
};
function AddToCal(){
//get the current row
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cell = ss.getActiveCell();
var R = cell.getRow();
//grab values for current row to pass to calendar event
var date_of_event = ss.getRange('G'+R).getValue();
var date = new Date(date_of_event);
var event_title = ss.getRange('A'+R).getValue();
//access the calendar
var cal = CalendarApp.getCalendarById('[IDREMOVED]');
cal.createAllDayEvent(event_title,date);
ss.toast("Event added to " + cal.getName());
}