13 January, 2010
0 Comments
0 categories
First I extracted some data from the outlook inbox with C# to a CSV file:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Outlook; using System.IO; namespace Common { public class Generator { const string Splitter = ","; const string CsvFIleName = "MailData.csv"; const string CsvPath = @"C:\BDATA"; public void Start() { Application outlook = new Application(); // Get the inbox folder MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); // Get received mails IEnumerable<Microsoft.Office.Interop.Outlook.MailItem> items = folder.Items.OfType<Microsoft.Office.Interop.Outlook.MailItem>(); // Clear file File.WriteAllText(Path.Combine(CsvPath, CsvFIleName), string.Empty); foreach (MailItem item in items) { StringBuilder csvContent = new StringBuilder(string.Empty); // Add [Sender] to output if (item.Sender != null && !string.IsNullOrEmpty(item.Sender.Name)) { csvContent.Append(item.Sender.Name.Replace(Splitter, string.Empty)); } csvContent.Append(Splitter); // Add [Subject] to output if (!string.IsNullOrEmpty(item.Subject)) { csvContent.Append(item.Subject.Replace(Splitter, string.Empty)); } csvContent.Append(Splitter); // Add [Year] to output csvContent.Append(item.ReceivedTime.Year); csvContent.Append(Splitter); // Add [Month] to output csvContent.Append(item.ReceivedTime.Month); csvContent.Append(Splitter); // Add [Day] to output csvContent.Append(item.ReceivedTime.Day); csvContent.Append(Splitter); // Add [Hour] to output csvContent.Append(item.ReceivedTime.Hour); // Per line export, so you will see the filesize grow on filesystem using (StreamWriter sw = File.AppendText(Path.Combine(CsvPath, CsvFIleName))) { sw.WriteLine(csvContent.ToString()); } } } } }
- Open the CSV file with Microsoft Office Excel 2010 and File > Save As “MailData.xlsx”
- Click on the ribbon tab [Data], select column A and then click on [Text to Columns]
- Click [Delimited] and click [Next]
- Uncheck [Tab] and check [Comma], then click [Next]
- Click Finish
- Result
- Press Ctrl + L to create a table
- Rename the generated column names (Column1 to Name etc.)
- Click on the excel tab [PowerPivot] and click on [Create Linked Table]
- In the powerpivot screen add column [Count] with formula [=1]
- Click on PivotTable to create a PowerPivot report in Microsoft Excel 2010
- Click on [Chart and Table (Horizontal)
- Click ok
- Select chart
- Drag and drop [Count] to [Values]
- Drag and drop [Name] to [Axis Fields (Categories)]
- Select chart and right click chart
- Click [Change Chart Type]
- Select Bar and click [OK]
- Click on [Name] in the chart
- Choose More Sort Options…
- Sort [Ascending (A to Z) by] [Sum of Count ]
- Again click on [Name] in the chart and click [Value Filters] [Greater Than]
- The email adresses in the screendumps are partial hidden, but you can see by hovering over the first bar, that [Heide] has send me the most messages [679]
- Select chart and Drag and drop [Hour] to [Slicers Horizontal]
- If you click on 12 in the hour slicer, you can see [Heide] had sent 49 mails on 12 o’clock
Tags: PowerPivot