【问题标题】:Include recurring appointments包括定期约会
【发布时间】:2019-06-24 17:22:50
【问题描述】:

我正在尝试使用 python 和 win32com 从客户端 Outlook 获取所有约会。客户,我只想获得 2019 年以来的所有约会,以便我可以限制约会项目,但是当我限制它们时,我没有得到定期约会。

我已经尝试通过约会启用定期项目。IncludeRecurrence = "True",但这没有帮助。

import win32com.client
import time
import datetime
import os


f=open("mem.txt", "w")
counter=0
outlook= win32com.client.Dispatch("Outlook.Application")
namespace=outlook.GetNamespace("MAPI")
recipient = namespace.createRecipient("Some Calender")
resolved = recipient.Resolve()
sharedCalendar = namespace.GetSharedDefaultFolder(recipient, 9)
appointments = sharedCalendar.Items

# Restrict items
begin = datetime.date(2019, 1, 1)
end = datetime.date(2019, 12, 30)
restriction = "[Start] >= '" + begin.strftime("%m/%d/%Y") + "' AND [End] <= '" +end.strftime("%m/%d/%Y") + "'"
restrictedItems = appointments.Restrict(restriction)
appointments.IncludeRecurrences = "True"

# Iterate through restricted AppointmentItems
for appointmentItem in restrictedItems:
    month= appointmentItem.Start
    month=str(month)[5:-18] #just trim the month out of the date
    if month=='08': #need appointments from specific
        #mystuff
        #the code works but I want the recurring appointments too
print(counter)
f.close()

【问题讨论】:

    标签: python outlook win32com


    【解决方案1】:

    您是否尝试在限制您的项目之前将IncludeRecurrences 设置为True

    基本上切换这两行:

    restrictedItems = appointments.Restrict(restriction)
    appointments.IncludeRecurrences = "True"
    

    【讨论】:

    • 你会读 C# 吗?我在 C# 中找到了相同问题的答案。它说在你的循环中添加一个 if-then 语句来评估 IsRecurring 属性:stackoverflow.com/a/8044268/11269264
    【解决方案2】:

    首先,要从满足预定义条件的文件夹中检索所有 Outlook 约会项目,您需要按升序对项目进行排序,并将 IncludeRecurrences 设置为 true。如果您在使用 Restrict 方法之前不这样做,您将不会赶上定期约会!

        folderItems = folder.Items;
        folderItems.IncludeRecurrences = true;
        folderItems.Sort("[Start]");
        resultItems = folderItems.Restrict(restrictCriteria);
    

    您可能会发现以下文章很有帮助:

    【讨论】:

      猜你喜欢
      • 2016-05-16
      • 2021-01-22
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多