c# 如何将共享 Outlook 日历导出到 Excel?

发布于 2024-11-26 05:28:58 字数 1465 浏览 0 评论 0原文

我希望能够将共享联系人的指定日历发送到 Excel。我可以发送日历中的信息,但无法发送共享联系人的日历。这是我自己的日历的代码:

    private void ButtonClick()
    {

        //open excel with 1 sheet
        Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
        excelApp.Visible = true;
        Microsoft.Office.Interop.Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

        Microsoft.Office.Interop.Excel.Worksheet caldendarWorksheet = newWorkbook.Sheets.Add(Type.Missing,Type.Missing,1,Type.Missing) as Microsoft.Office.Interop.Excel.Worksheet;
        caldendarWorksheet.Name = "CalendarView";

        //accesses outlook to get the calendar

        Microsoft.Office.Interop.Outlook.Application ol = null;
        Microsoft.Office.Interop.Outlook.MAPIFolder blab = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

        Microsoft.Office.Interop.Outlook.Items ItemGet = blab.Items.Restrict("[MessageClass]='IPM.Appointment'");
        Microsoft.Office.Interop.Outlook.Items ItemGet = blab.Items;
        int iNumContacts = ItemGet.Count;

        if (iNumContacts != 0)
        {
            // the index i is 1-iNumContacts,
            int i = 1;
            Microsoft.Office.Interop.Outlook.AppointmentItem c = ItemGet[i] as Microsoft.Office.Interop.Outlook.AppointmentItem;



        }

    }

这只适用于我的个人日历。

I want to be able to send a designated calendar of a shared contact to Excel. I can send information from my calendar but cannot send the calendar of a shared contact. This is the code I have for my own calendar:

    private void ButtonClick()
    {

        //open excel with 1 sheet
        Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
        excelApp.Visible = true;
        Microsoft.Office.Interop.Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

        Microsoft.Office.Interop.Excel.Worksheet caldendarWorksheet = newWorkbook.Sheets.Add(Type.Missing,Type.Missing,1,Type.Missing) as Microsoft.Office.Interop.Excel.Worksheet;
        caldendarWorksheet.Name = "CalendarView";

        //accesses outlook to get the calendar

        Microsoft.Office.Interop.Outlook.Application ol = null;
        Microsoft.Office.Interop.Outlook.MAPIFolder blab = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

        Microsoft.Office.Interop.Outlook.Items ItemGet = blab.Items.Restrict("[MessageClass]='IPM.Appointment'");
        Microsoft.Office.Interop.Outlook.Items ItemGet = blab.Items;
        int iNumContacts = ItemGet.Count;

        if (iNumContacts != 0)
        {
            // the index i is 1-iNumContacts,
            int i = 1;
            Microsoft.Office.Interop.Outlook.AppointmentItem c = ItemGet[i] as Microsoft.Office.Interop.Outlook.AppointmentItem;



        }

    }

This only works for my personal calendar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2024-12-03 05:28:58

在您的代码中,您不登录联系人的帐户,而是登录计算机上默认/当前打开的任何帐户...您需要在此行中指定联系人的日历(需要足够的权限!)

 Microsoft.Office.Interop.Outlook.MAPIFolder blab = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

in your code you don't login to the account of the contact but to whatever account is default/currently open on the computer... you need to specify the calendat of the contact in this line (sufficient rights needed!)

 Microsoft.Office.Interop.Outlook.MAPIFolder blab = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文