protected void InitHead() { Type type = typeof(THead); PropertyInfo[] PropertyList = type.GetProperties(); int columnIndex = 0; foreach (PropertyInfo item in PropertyList) { if (ExcelHeadNotContainedTypeFactory.GetExceptedTypes().Contains(item.PropertyType)) { continue; } headNames.Add(item.Name, columnIndex); headLine.CreateCell(columnIndex).SetCellValue(item.Name); columnIndex++; } if (columnIndex == 0) { throw new Exception(new StringBuilder().AppendFormat("Class: {0} 没有任何有效属性。", type.Name).ToString()); } currentRowIndex++; }
public SingleSheetExcelGroupedReportingScaffold(List <TFather> fathers, List <TChild> childs, string groupField) : this() { if (fathers == null || childs == null) { throw new ArgumentNullException(); } _fatherSource = fathers; _childSource = childs; _groupField = groupField; fatherType = typeof(TFather); childType = typeof(TChild); fatherPropertys = fatherType.GetProperties(); childPropertys = childType.GetProperties(); childHeadNames = new Dictionary <string, int>(); int currentColumnInex = 0; foreach (var prop in childPropertys) { if (prop.Name == _groupField) { continue; } if (ExcelHeadNotContainedTypeFactory.GetExceptedTypes().Contains(prop.PropertyType)) { continue; } childHeadNames.Add(prop.Name, currentColumnInex); currentColumnInex++; } Check(); GenerateExecelContent(); }
public SingelSheetExcelScaffold(string sheetname) { headNames = new Dictionary <string, int>(); workbook = new HSSFWorkbook(); if (!IsSheetExist()) { sheet = workbook.CreateSheet(sheetname); } headLine = sheet.CreateRow(0); ExcelHeadNotContainedTypeFactory.AddExceptType(typeof(Guid)); InitHead(); }