private void PullDataFromAttributeAuditDetail(AttributeAuditDetail attributeDetail, Microsoft.Office.Interop.Excel._Worksheet workSheet, string title) { var AttributeColl = attributeDetail.OldValue.Attributes; if (ColumnCount != AttributeColl.Count) { // Add Columns foreach (var ColumnName in AttributeColl.Keys) { if (!ColumnSet.ContainsKey(ColumnName)) { ColumnCount++; string attributeType = AttributeColl[ColumnName].GetType().ToString(); if (attributeType == "Microsoft.Xrm.Sdk.EntityReference") { ColumnSet.Add(ColumnName, new List <ColumnDetail>() { new ColumnDetail() { AttributeName = ColumnName, Column = ColumnName + "_GUID", position = ColumnCount }, new ColumnDetail() { AttributeName = ColumnName, Column = ColumnName + "_Name", position = (ColumnCount + 1) } }); workSheet.Cells[1, ExcelColumns[ColumnCount + 1]] = ColumnName + "_GUID"; workSheet.Cells[1, ExcelColumns[ColumnCount + 2]] = ColumnName + "_Name"; ColumnCount++; } else { ColumnSet.Add(ColumnName, new List <ColumnDetail>() { new ColumnDetail() { AttributeName = ColumnName, Column = ColumnName, position = ColumnCount } }); workSheet.Cells[1, ExcelColumns[ColumnCount + 1]] = ColumnName; } } } } workSheet.Cells[rowCount, "A"] = title; foreach (KeyValuePair <string, List <ColumnDetail> > item in ColumnSet) { string cellValue = ""; if (AttributeColl.ContainsKey(item.Key)) { var attribute = AttributeColl[item.Key]; switch (attribute.GetType().ToString()) { case "Microsoft.Xrm.Sdk.OptionSetValue": cellValue = ((OptionSetValue)attribute).Value.ToString(); break; case "Microsoft.Xrm.Sdk.EntityReference": var ref_ = (EntityReference)attribute; workSheet.Cells[rowCount, ExcelColumns[item.Value[1].position + 1]] = ref_.Name; cellValue = ref_.Id.ToString(); break; default: cellValue = attribute.ToString(); break; } workSheet.Cells[rowCount, ExcelColumns[item.Value[0].position + 1]] = cellValue; } } rowCount++; }