0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GAS】スプレッドシートの行データからGoogleカレンダーへ予定を一括自動登録する方法(招待メール・重複防止対応)

0
Posted at

はじめに
スプレッドシートにまとめたイベント・面談・タスク一覧から、Google Apps Script(GAS)を使ってGoogleカレンダーへ予定を一括登録する仕組みを解説します。

主な処理フロー
SpreadsheetApp でシートの行データを一括配列取得

ヘッダー行から各項目(タイトル、日時、場所、参加者等)の列インデックスを動的に取得

CalendarApp.getDefaultCalendar() または getCalendarById() を使用

終日イベント(createAllDayEvent)と時間指定イベント(createEvent)を条件分岐で作成

登録完了した行に「登録済み」ステータスと「イベントID」を書き込んで重複登録を防止

コアロジック(サンプルコード)

function bulkAddEvents() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
const calendar = CalendarApp.getDefaultCalendar();

for (let i = 1; i < data.length; i++) {
const [title, startTime, endTime, isAllDay, location, desc, guests, status] = data[i];
if (status === '登録済み' || !title || !startTime) continue;

const options = { location: location, description: desc, guests: guests, sendInvites: true };

if (isAllDay) {
  calendar.createAllDayEvent(title, new Date(startTime), options);
} else {
  const end = endTime ? new Date(endTime) : new Date(new Date(startTime).getTime() + 3600000);
  calendar.createEvent(title, new Date(startTime), end, options);
}

sheet.getRange(i + 1, 8).setValue('登録済み');

}
}

まとめ・カスタムメニュー付き完全版
エラーハンドリング、終日判定の柔軟化、スプレッドシートUIメニュー拡張などを組み込んだ完全版コードと導入ガイドは note(B2B Tools) にて公開しています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?