1

我想將谷歌錶鏈接到日曆以自動創建日曆事件並在谷歌表格中更新它們時更新它們。我的Google表格會跟蹤新的建築開幕日期和新的建築開始日期,因此我需要它在適用的時候創建兩個日曆活動(有時只填寫其中一個日期)。鏈接谷歌表來自動創建日曆事件,並在谷歌表更新時更新它們

工作表的標題是「Loc。#」,「Location」,「Cons Start」和「Whse Open」。 這些標題中的每一個的值均從對不同工作表的引用填充,並且由於是引用而自動從該工作表進行更新。

我不是最傾向於在JavaScript,但到目前爲止,我對谷歌的代碼應用腳本如下:

// Calendar ID can be found in the "Calendar Address" section of the Calendar Settings. 
var calendarId = '[email protected]'; 

// 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; 
} 

不能確定接下來要做到這一點做什麼。關於如何實現這個的任何建議?

回答

1

您可以嘗試查看這些教程和SO如何使用Google Apps腳本創建日曆活動的問題。這些鏈接包含一些您可以複製的示例代碼。

更多informationor更多的想法,你也可以檢查如何使用Google Apps Script in creating a calendar events from Google Form這個教程。