c# 如何将共享 Outlook 日历导出到 Excel?
我希望能够将共享联系人的指定日历发送到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,您不登录联系人的帐户,而是登录计算机上默认/当前打开的任何帐户...您需要在此行中指定联系人的日历(需要足够的权限!)
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!)