我正在使用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)
从描述Outlook的this链接中,我发现我可以获得AppointmentItem对象的大小。但是它抛出了一个异常
AttributeError: '<win32com.gen_py.Microsoft Outlook 15.0 Object Library._Items instance at 0x73837256>' object has no attribute 'size'
我做错了什么?
顺便说一下,我想使用它来检查作为上述查询的结果而检索到的任何约会,这样我就不会在None
上使用restriction
对象。
发布于 2018-06-09 04:02:53
Restrict
返回Items集合。它不会公开Size属性--您需要的是Count
。
如果事先不知道集合的大小(Outlook按需计算),则使用Items.GetFirst/GetNext
遍历集合中的项。
https://stackoverflow.com/questions/50740835
复制相似问题