.NET:获取所有 Outlook 日历项目
如何获取特定日历(特定日期)的所有项目。 举例来说,我有一个日历,每个星期一晚上都有一个重复出现的项目。 当我请求这样的所有项目时:
CalendarItems = CalendarFolder.Items;
CalendarItems.IncludeRecurrences = true;
我只获得 1 个项目...
是否有一种简单的方法可以从日历中获取所有 项目(主项目 + 派生项目)? 在我的具体情况下,可以设置日期限制,但获取所有项目会很酷(我的重复项目本身有时间限制)。
我正在使用 Microsoft Outlook 12 对象库 (Microsoft.Office.Interop.Outlook)。
How can I get all items from a specific calendar (for a specific date).
Lets say for instance that I have a calendar with a recurring item every Monday evening. When I request all items like this:
CalendarItems = CalendarFolder.Items;
CalendarItems.IncludeRecurrences = true;
I only get 1 item...
Is there an easy way to get all items (main item + derived items) from a calendar?
In my specific situation it can be possible to set a date limit but it would be cool just to get all items (my recurring items are time limited themselves).
I'm using the Microsoft Outlook 12 Object library (Microsoft.Office.Interop.Outlook).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我发现这篇文章非常有用:https://learn.microsoft.com/en-us/office/client-developer/outlook/pia/how-to-search-and-obtain-appointments-in -a-time-range
演示如何获取指定时间范围内的日历条目。 这对我有用。 为了您的方便,这里是文章的源代码:)
I found this article very useful: https://learn.microsoft.com/en-us/office/client-developer/outlook/pia/how-to-search-and-obtain-appointments-in-a-time-range
It demonstrates how to get calendar entries in a specified time range. It worked for me. Here is the source code from the article for your convenience :)
我相信您必须限制或查找才能获得定期约会,否则 Outlook 将不会扩展它们。 此外,您必须在设置 IncludeRecurrences 之前按开始排序。
I believe that you must Restrict or Find in order to get recurring appointments, otherwise Outlook won't expand them. Also, you must Sort by Start before setting IncludeRecurrences.
我写了类似的代码,但后来发现了导出功能:
I wrote similar code, but then found the export functionality:
LinqPad 剪裁对我有用:
LinqPad snipped that works for me:
如果您需要访问您朋友的共享文件夹,您可以将您的朋友设置为收件人。 要求:必须首先共享他的日历。
If you need want to access the shared folder from your friend, then you can set your friend as the recipient. Requirement: his calendar must be shared first.
无需手动扩展重复项目。 只需确保您在使用 IncludeRecurrences 之前对项目进行排序即可。
这是 VBA 示例:
There is no need to expand recurring items manually. Just ensure you sort the items before using IncludeRecurrences.
Here is VBA example:
我研究了文档,这是我的结果:
我已经硬编码了一个月的时间限制,但这只是一个例子。
I've studied the docs and this is my result:
I've put a time limit of one month hard-coded, but this is just an example.
尝试这个:
Try this:
以下是获取过去 30 天内条目的一些答案的组合。 将输出到控制台,但您可以将控制台日志输出保存到文件或您想要的任何内容。 感谢大家在这里发布他们的代码,非常有帮助!
Here's a combination of a few answers to get entries from the past 30 days. Will output to console but you can take the console log output and save to a file or whatever you want from there. Thanks to everyone for posting their code here, was very helpful!