Title1

Title2

Title3

6-3 宣告 設定Google日曆函式 所需變數

宣告變數


// 請自行更換 Google日曆ID
let calendarId = 'Google日曆ID';

// 宣告用 預約日期 開始時間 結束時間 標題 時段
let bookingDate = startTime = endTime = calendarTitle = period = '';

// 宣告用 description location
let options = {};

// 請自行更換 活動地點(可不填)
options.location = '';

// 請自行更換 設定形成顏色(1~11)
options.color = 4;

整理資料


  // 整理line 通知 訊息
  head.forEach((headItem, index) => {
    if (headItem === "時間戳記") {
      row[index] = Utilities.formatDate(row[index], "GMT+08:00", 'yyyy-MM-dd HH:mm:ss');
    }

    if (headItem === "預約日期") {
      row[index] = Utilities.formatDate(row[index], "GMT+08:00", 'yyyy-MM-dd');
      bookingDate = row[index];
    }

    if (headItem === "服務項目") {
      calendarTitle = row[index];
    }

    if (headItem === "預約時段") {
      period = row[index];
      // 以 "-" 為分隔符號,將時間區間分割成開始時間和結束時間
      let timeArray = row[index].split("-");
      // 開始時間為陣列的第一個元素
      startTime = timeArray[0];
      // 結束時間為陣列的第二個元素
      endTime = timeArray[1];
    }

    if (headItem === "備註事項") {
      options.description = row[index];
    }

    message += "\n" + headItem + ": " + row[index];
  });

調用函式


  // 判斷 開始日期時間 結束日期時間
  if(bookingDate && startTime){
    startTime = bookingDate + ' ' + startTime;
    calendarTitle += "-" + period;
    if(endTime){
      endTime = bookingDate + ' ' + endTime;
    }else{
      endTime = '';
    }
  }else{
    startTime = endTime = '';
  }
  
  // 執行Google日曆通知
  if(calendarId && calendarTitle && startTime){
    setCalendar(calendarId, calendarTitle, startTime, endTime, options)
  }