2
3

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 1 year has passed since last update.

[Python]Outlookの予定表から日付範囲を指定して予定を吸い上げる方法

Last updated at Posted at 2022-04-14

この記事でやっているような全部吸い上げてからpythonでフィルタリングする方法よりも、下のコードで示すようなItems.Restrict()を使用する方が高速らしい

import win32com.client
import datetime

# 調べたい日付範囲を定義
start_date = datetime.date(2022, 4, 1)
end_date = datetime.date(2022, 4, 30)

# Outlookの予定表へのインタフェースオブジェクトを取得
Outlook = win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
CalendarItems = Outlook.GetDefaultFolder(9).Items

# 定期的な予定の二番目以降の予定を検索に含める
CalendarItems.IncludeRecurrences = True

# 開始時間でソート
CalendarItems.Sort("[Start]")

# "mm/dd/yyyy HH:MM AM"の形式に変換し、フィルター文字列を作成
strStart = start_date.strftime('%m/%d/%Y %H:%M %p')
strEnd = end_date.strftime('%m/%d/%Y %H:%M %p')
sFilter = f"[Start] >= '{strStart}' And [End] <= '{strEnd}'"

# フィルターを適用し表示
FilteredItems = CalendarItems.Restrict(sFilter)
for item in FilteredItems:
	print(str(item.Start.Format("%Y/%m/%d %H:%M")) + " : " + str(item.Subject))
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?