private List <ExcelSheet> GetExcelsOnlyTop(ParseParam param) { List <ExcelSheet> sheets = new List <ExcelSheet>(); var allConfigs = Directory.GetFiles(param.ExcelDir, "*.*", SearchOption.TopDirectoryOnly).Where(s => !string.IsNullOrEmpty(Path.GetExtension(s)) && SUPPORTED_EXTENSIONS.Contains(Path.GetExtension(s).ToLower()) && !s.Contains("~")); foreach (var configPath in allConfigs) { string workbookName = Path.GetFileNameWithoutExtension(configPath); using (FileStream fs = new FileStream(configPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IWorkbook workbook = WorkbookFactory.Create(fs); for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++) { ISheet sheet = workbook.GetSheetAt(sheetIndex); if (sheet.PhysicalNumberOfRows == 0) { continue; } for (int rowIndex = sheet.FirstRowNum; rowIndex <= sheet.LastRowNum;) { IRow row = sheet.GetRow(rowIndex++); if (row == null) { continue; } ICell cell = row.GetCell(0); //寻找以[Config]为标记的首行 if (cell == null || cell.CellType != CellType.String) { continue; } if (cell.GetStringCellValue().Trim() == "[ExcelLENT]") { ExcelSheet excelSheet = new ExcelSheet() { Workbook = workbook, Sheet = sheet, ClassName = row.GetCell(1, MissingCellPolicy.CREATE_NULL_AS_BLANK).GetStringCellValue(), m_primaryKeyRow = sheet.GetRow(rowIndex++), CustomTypeRow = sheet.GetRow(rowIndex++), FieldTypeRow = sheet.GetRow(rowIndex++), FieldNameRow = sheet.GetRow(rowIndex++), FieldDescriptionRow = sheet.GetRow(rowIndex++), ContentBeginRowNum = rowIndex, ContentEndRowNum = sheet.LastRowNum, }; sheets.Add(excelSheet); excelSheet.Close(); break; } } } } } return(sheets); }
public SerializationException(ExcelSheet sheet, int rowNum, BaseField field, Exception inner) : base($"Sheet:`{sheet.Sheet.SheetName}`, RowNum:`{rowNum + 1}`, Field:`{field.Name}`", inner) { }