我正在使用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)
从这个描述 AppointmentItem API 的链接中,我发现我可以获取 Outlook 对象的大小。但是会抛出异常
AttributeError: '<win32com.gen_py.Microsoft Outlook 15.0 Object Library._Items instance at 0x73837256>' object has no attribute 'size'
我究竟做错了什么?
顺便说一下,我想使用它来检查作为上述查询的结果检索到的任何约会,以便我不会restriction
在None
.
Restrict
返回项目集合。它不公开 Size 属性 - 您需要的是Count
.
如果提前不知道集合的大小(Outlook 按需计算),请使用Items.GetFirst/GetNext
循环遍历集合中的项目。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句