public static ExcelRangeBase LoadWithCustomHeaders <T>(this ExcelRangeBase excelRange, IEnumerable <T> list) { excelRange.LoadFromCollection(list, true); const int Row = 1; int columnsCount = excelRange.Worksheet.Cells.Count() / list.Count(); for (int column = 1; column <= columnsCount; column++) { string incorrectHeader = excelRange.Worksheet.Cells[Row, column].Text; PropertyInfo[] Properties = typeof(T).GetProperties(); foreach (PropertyInfo Property in Properties) { if (incorrectHeader == Property.Name.Replace('_', ' ')) { object[] DisplayAttributes = Property.GetCustomAttributes(typeof(DisplayAttribute), true); if (DisplayAttributes.Length == 1) { excelRange.Worksheet.Cells[Row, column].Value = ((DisplayAttribute)(DisplayAttributes[0])).Name; break; } } } } return(excelRange); }
public static ExcelRangeBase LoadFromCollectionFiltered <T>(this ExcelRangeBase @this, IEnumerable <T> collection) where T : class { MemberInfo[] membersToInclude = typeof(T) .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(p => !Attribute.IsDefined(p, typeof(EpplusIgnore))) .ToArray(); return(@this.LoadFromCollection <T>(collection, false, OfficeOpenXml.Table.TableStyles.None, BindingFlags.Instance | BindingFlags.Public, membersToInclude)); }
public static ExcelRangeBase LoadFromCollectionFiltered <T>(this ExcelRangeBase @this, IEnumerable <T> collection, bool printHeader, TableStyles style) where T : class { var type = typeof(T); MemberInfo[] membersToInclude = typeof(T) .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(p => !Attribute.IsDefined(p, typeof(EpplusIgnore))) .ToArray(); return(@this.LoadFromCollection <T>(collection, printHeader, style, BindingFlags.Instance | BindingFlags.Public, membersToInclude)); }
/// <summary> /// Set default table style in LoadFromCollection method, third parameter. /// </summary> public static ExcelRangeBase LoadFromCollectionFiltered <T>(this ExcelRangeBase @this, IEnumerable <T> collection) { MemberInfo[] membersToInclude = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(x => !Attribute.IsDefined(x, typeof(ExcelIgnore))).ToArray(); return(@this.LoadFromCollection(collection, true, OfficeOpenXml.Table.TableStyles.Dark2, BindingFlags.Instance | BindingFlags.Public, membersToInclude)); }