获取 Outlook 约会后无法调用 win32com.client.Dispatch AppointmentItem 的 'Size' 属性

Cannot call 'Size' property of win32com.client.Dispatch AppointmentItem after getting Outlook Appointments

我正在使用 win32com.client 访问 Outlook 应用程序。我成功地设法从日历中获取约会,但我有兴趣在不进入 for 循环的情况下获取约会数量。

我正在做以下事情:

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace('MAPI')

appointments = namespace.GetDefaultFolder(9).Items

appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"

restriction = "[Start] >= '" + start_date.strftime('%Y.%m.%d') + "' AND [Start] <= '" + \
              end_date.strftime('%Y.%m.%d') + "'"
restricted_items = appointments.Restrict(restriction)
print(restricted_items.Size)

this link 描述 AppointmentItem API,我发现我可以得到 Outlook 对象的大小。但是它抛出一个异常

AttributeError: '<win32com.gen_py.Microsoft Outlook 15.0 Object Library._Items instance at 0x73837256>' object has no attribute 'size'

我做错了什么?

顺便说一句,我想用它来检查作为上述查询结果检索到的任何约会,这样我就不会在 None 上使用 restriction 对象。

RestrictreturnItemscollection。它不公开大小 属性 - 你需要的是 Count.

如果事先不知道collection的大小(Outlook按需计算),使用Items.GetFirst/GetNext循环遍历collection中的项目。