private ISheet AddValue(ISheet sheet, ISheetDataWrapper sheetDetailDataWrapper, Type type) { IList <PropertyInfo> checkPropertyInfos = ExcelModelsPropertyManage.CreatePropertyInfos(type); Int32 cellCount = 0; foreach (var item in sheetDetailDataWrapper.Datas) { if (item == null) { StartRow++; continue; } IRow newRow = sheet.CreateRow(StartRow); buildContext.Row = newRow; foreach (PropertyInfo property in checkPropertyInfos) { Object obj = property.GetValue(item, null); Type t = property.PropertyType; ICell cell; if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable <>)) { var ssd = ((IEnumerable)obj).Cast <IExtendedBase>(); if (ssd == null) { continue; } foreach (var v in sheetDetailDataWrapper.Titles) { IExtendedBase sv = ssd.Where(s => s.TypeId == v.TypeId).SingleOrDefault(); SetCell(newRow, cellCount++, sv.TypeValue); } continue; } SetCell(newRow, cellCount++, obj); } StartRow++; cellCount = 0; } return(sheet); }
public SheetDetail(String sheetName, ISheetDataWrapper datas) : this(sheetName, new SheetDataCollection()) { this.SheetDetailDataWrappers.Add(datas); }
private ISheet AddValue(ISheet sheet, ISheetDataWrapper sheetDetailDataWrapper, Type type) { IList <PropertyInfoDetail> checkPropertyInfos = ExcelModelsPropertyManage.CreatePropertyInfos(type); Int32 cellCount = 0; foreach (var item in sheetDetailDataWrapper.Datas) { if (item == null) { _startRow++; continue; } IRow newRow = sheet.CreateRow(_startRow); _buildContext.Row = newRow; foreach (PropertyInfoDetail propertyInfoDeatil in checkPropertyInfos) { Object obj = propertyInfoDeatil.PropertyInfoV.GetValue(item, null); Type t = propertyInfoDeatil.PropertyInfoV.PropertyType; if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable <>)) { var ssd = ((IEnumerable)obj).Cast <IExtendedBase>(); if (ssd == null) { continue; } foreach (var title in sheetDetailDataWrapper.Titles) { IExtendedBase sv = ssd.SingleOrDefault(s => s.TypeId == title.TypeId); Object val = null; if (sv == null || sv.TypeValue == null) { val = ExcelModelsPropertyManage.GetExtendedDefaultValue(title.GetType()); } else { val = sv.TypeValue; } SetCell(newRow, cellCount++, val); } continue; } SetCell(newRow, cellCount++, obj == null && propertyInfoDeatil.DefaultVale != null ? propertyInfoDeatil.DefaultVale : obj); } _startRow++; cellCount = 0; } return(sheet); }
private ISheet SetTitle(ISheet sheet, ISheetDataWrapper sheetDetailDataWrapper, Type type) { IRow titleRow = null; ICell titleCell = null; if (!String.IsNullOrEmpty(sheetDetailDataWrapper.DataName)) { titleRow = sheet.CreateRow(StartRow); buildContext.Row = titleRow; StartRow++; titleCell = SetCell(titleRow, 0, sheetDetailDataWrapper.DataName); if (OnHeadCellSetAfter != null) { OnHeadCellSetAfter(buildContext); } } IRow row = sheet.CreateRow(StartRow); buildContext.Row = row; IList <PropertyInfo> checkPropertyInfos = ExcelModelsPropertyManage.CreatePropertyInfos(type); int i = 0; foreach (PropertyInfo property in checkPropertyInfos) { DisplayNameAttribute dn = property.GetCustomAttributes(typeof(DisplayNameAttribute), false).SingleOrDefault() as DisplayNameAttribute; if (dn != null) { SetCell(row, i++, dn.DisplayName); continue; } Type t = property.PropertyType; if (t.IsGenericType) { if (sheetDetailDataWrapper.Titles == null || sheetDetailDataWrapper.Titles.Count() == 0) { continue; } foreach (var item in sheetDetailDataWrapper.Titles) { SetCell(row, i++, item.TypeName); } } } if (titleCell != null && i > 0) { titleCell.MergeTo(titleRow.CreateCell(i - 1)); titleCell.CellStyle = this.CenterStyle; } StartRow++; return(sheet); }