So far, all my Outlook add-in posts have covered different aspects of gathering data from the user. It would also be nice if the user could get some nice presentation of this data, making it worthwhile putting it in. For this I have chosen to implement a custom task pane, that I have added and only displays when the calendar is active.
The graph shows how I have spent my time for the time period in the datetime pickers. There is a new DisplayedDates property on the CalendarView that is supposed to return the dates displayed in the calendar, but unfortunately it does not work, and it is a confirmed bug.
Below the graph I have a couple of different possibilities to export the data to some Excel-files and also to send an e-mail with invoice information to the person responsible of doing invoicing. All the Excel-files are created with code and I have a reference set to the Excel interop assembly.
//Task Pane
taskPane = this.CustomTaskPanes.Add(new IRM.Office.Outlook.WorkItemOverview(this.calendar), "IRM");
taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
//Hook events
explorer = Application.ActiveExplorer();
explorer.BeforeFolderSwitch += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_BeforeFolderSwitchEventHandler(explorer_BeforeFolderSwitch);
The task pane user interface is just a regular user control. The last two lines catches the BeforeFolderSwitchEvent in which I hides or shows the task pane depending on the selected folder.
bool isInCalendar = ((MSOutlook.Folder)newFolder).Name == calendar.Name;
this.taskPane.Visible = isInCalendar;
To gather the information from the calendar I'm using the new Table, and the just loops through the rows extracting my attachments.
public static MSOutlook.Table GetAppoinmentsForPeriod(DateTime start, DateTime end)
{
MSOutlook.Folder calendar = IRM.Outlook.Globals.ThisAddIn.Calendar;
System.Globalization.CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture;
string filter = string.Format(@"[Start] > ""{0}"" And [End] < ""{1}""", start.AddMinutes(-1).ToString("d", culture), end.AddDays(1).ToString("d", culture));
MSOutlook.Table table = calendar.GetTable(filter, MSOutlook.OlTableContents.olUserItems);
table.Columns.RemoveAll();
table.Columns.Add("EntryID");
table.Columns.Add("Start");
table.Columns.Add("End");
table.Columns.Add("Sensitivity");
table.Sort("Start", Type.Missing);
return table;
}
In the code above I first define my query, getting the table, choosing the columns I'm interested in and finally setting the sort order.
This is probably my last Outlook post for a while, since I have covered the most interesting parts of my add-in. I have used it for three months soon and it works great, and as I wrote in my
first post I'm quite impressed of how far Microsoft have come with Outlook extensibility.