#Python #Outlook #カレンダー管理 #自動化 #API
Outlookの予定表をPythonで操作する方法を紹介!Microsoft Graph APIやwin32comを使い、スケジュールの追加・更新を自動化します。
#python #Outlook #プログラミング
import win32com.client
from datetime import datetime, timedelta
# Outlookアプリケーションのインスタンスを作成
outlook = win32com.client.Dispatch(“Outlook.Application”)
namespace = outlook.GetNamespace(“MAPI”)
# カレンダーアイテムを作成
appointment = outlook.CreateItem(1) # 1 は「予定」のアイテムタイプ
# 予定の詳細設定
appointment.Subject = “新しい予定” # 予定のタイトル
appointment.Start = datetime(2025, 3, 10, 9, 0) # 開始時間(例: 2025-03-10 09:00)
appointment.End = datetime(2025, 3, 10, 15, 0) # 終了時間(例: 2025-03-10 15:00)
appointment.Location = “会議室” # 場所
appointment.Body = “会議の内容” # 説明
appointment.Save() # 予定を保存
appointment.Send() # 送信(参加者がいれば)
print(“予定が追加されました。”)
# UTCを取得して日本時間に変換
appointment_start = appointment.Start.astimezone(pytz.utc).astimezone(local_timezone)
appointment_end = appointment.End.astimezone(pytz.utc).astimezone(local_timezone)




