简体   繁体   English

当我点击它时,如何在 Outlook 日历中获取选定的约会(ID?)?

[英]How can I get the selected appointment (Id?) in Outlook calendar when i click on it?

I can get a list of all calendar items but how can i pick the right one?我可以获得所有日历项目的列表,但我如何才能选择正确的项目? How can i compare the IDs within the collection and the on screen clicked?我如何比较集合中的 ID 和点击的屏幕?

public void OnActionCallback(IRibbonControl control, bool isPressed)
        {
            _Outlook.Application oApp = null;
            oApp = new _Outlook.Application();
            var appointments = oApp.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar).Items;

            foreach (AppointmentItem item in appointments)
            {
                JobTimeLine j = new JobTimeLine() 
                {
                    PostingDate = item.Start,
                    No = item.RequiredAttendees,
                    WorkTypeCode=item.Subject,
                    FromTime=item.Start.ToLocalTime(),
                    ToTime=item.End.ToLocalTime(),
                    ShipToName = null,
                    JobNo = item.ConversationTopic,
                    JobTaskNo = item.Body,
                    PlaceOfWork = "Büro",
                    Description= null,
                    Description2= null,
                    ShipToCostumerNo= "D20101",
                };

            MessageBox.Show("GlobalAppointmentID = " + item.GlobalAppointmentID + j.GetOutput());
            }
}

I am getting a collection but i need to pick exactly one item from it, which is clicked/selected/loaded in the outlook app.我正在收集一个集合,但我需要从中选择一个项目,在 outlook 应用程序中单击/选择/加载。

The currently selected items in the Outlook explorer view can be retrieved by using the Selection property of the Explorer class which returns a Selection object that contains the item or items that are selected in the explorer window. The location of a selection in the explorer can be in the view list, the appointment list or task list in the To-Do Bar, or the daily tasks list in a calendar view.可以使用Explorer class 的选择属性检索当前在 Outlook 资源管理器视图中选择的项目,该属性返回一个Selection object,其中包含在资源管理器 window 中选择的一个或多个项目。选择在资源管理器中的位置可以是在视图列表中,待办事项栏中的约会列表或任务列表,或日历视图中的日常任务列表。 For more information, see the Location property.有关详细信息,请参阅位置属性。

private void DisplaySelectedItems()
{
    Outlook.Selection selection =
        Application.ActiveExplorer().Selection;
    for (int i = 1; i <= selection.Count; i++)
    {
        object myItem = selection[i];
    }
}

To get items displayed in the inspector windows in Outlook you may use the CurrentItem property of the Inspector class (see the ActiveInspector method of the Outlook Application class).要在 Outlook 的检查器 windows 中显示项目,您可以使用Inspector class 的CurrentItem属性(请参阅 Outlook Application类的ActiveInspector方法)。

Also in the code I've noticed that a new Outlook Application instance is created:同样在代码中,我注意到创建了一个新的 Outlook Application 实例:

_Outlook.Application oApp = null;
            oApp = new _Outlook.Application();

In the ribbon callbacks you can use the Application property of your add-in class or just access it by using the Globals static class in the following way:在功能区回调中,您可以使用加载项 class 的Application属性,或者仅通过以下方式使用Globals变量 static class 访问它:

Globals.ThisAddIn.Application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM