我希望能够将指定的共享联系人日历发送到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;
}
}
这仅适用于我的个人日历。
答案 0 :(得分:1)
在您的代码中,您没有登录到联系人的帐户,而是登录到计算机上默认/当前打开的任何帐户...您需要在此行中指定联系人的日历(需要足够的权限!)
Microsoft.Office.Interop.Outlook.MAPIFolder blab = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);