欄位對應:
GAS:
var token = "Line Notify權杖";
function getFormData(e) {
var ss = SpreadsheetApp.getActive();
var ws = ss.getActiveSheet();
var lastColumn = ws.getLastColumn();
var datas = ws.getSheetValues(1, 1, 1, lastColumn);
var message = "\n\n";
for (var i = 0 ; i < lastColumn; i++) {
message += datas[0][i] + ":" + e.values[i] + "\n\n";
}
sendLineNotify(message);
var title = e.values[2] + "-" + e.values[4]; //日曆標題
var startDate = e.values[3];//日期
var description = e.values[2] + "-" + e.values[3] + "--" + e.values[4];//日曆內容
var color = 11;
setCalendar(title, startDate, description, color);
}
function sendLineNotify(message){
var options =
{
"method" : "post",
"payload" : {"message" : message},
"headers" : {"Authorization" : "Bearer " + token}
};
UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}
var googleCalendarID = "Google日曆id";//日曆id
function setCalendar(title, startDate, description, color) {
startDate = new Date(startDate.replace(/-/g, "/"));//轉換日期格式
//透過ID取得日曆
var cal = CalendarApp.getCalendarById(googleCalendarID);
//沒有結束日期的全天事件
var even = cal.createAllDayEvent(title, startDate, {description:description});
//設定形成顏色
even.setColor(color);
}