8
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

googleカレンダーから予定を取得する

Last updated at Posted at 2017-05-05

概要

スプレッドシートにgoogleカレンダーの予定を出力する。

calendar.gs
function fetchSchedules() {
  // メールアドレス
  var EMAIL = 'xxxxxx@gmail.com';

  // スプレッドシート:シート名
  var SHEET_NAME = 'schedule';
  // スプレッドシート:開始位置
  var RANGE = 2;  
  // スプレッドシート:時間フォーマット
  var FORMAT_TIME = 'hh:mm';

  // シート情報を取得
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME).clear();
  // カレンダー情報を取得
  var calender = CalendarApp.getCalendarById(EMAIL);
  // 当日の予定を取得
  var schedules = calender.getEventsForDay(new Date());
  
  // 予定を繰り返し出力する
  for(var index = 0; index < schedules.length; index++) {
    var range = RANGE + index;
    // 開始時間を出力
    sheet.getRange(range, 3).setValue(schedules[index].getStartTime()).setNumberFormat(FORMAT_TIME);
    // 終了時間を出力
    sheet.getRange(range, 4).setValue(schedules[index].getEndTime()).setNumberFormat(FORMAT_TIME);
    // 予定名を出力
    sheet.getRange(range, 5).setValue(schedules[index].getTitle());
  }  
}
8
16
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
8
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?