private IEnumerable <IDataSheetRow> GetRowsWithData(IDataSheet worksheet) { var firstRow = worksheet.FirstRowUsed().RowNumber + 1; var lastRow = worksheet.LastRowUsed().RowNumber; var rows = worksheet.Rows(firstRow, lastRow); return(rows); }
private IDictionary <string, CellToPropertyMap> InternalCreatePropertyMap <TModel>(IDataSheet worksheet, IReadOnlyList <MemberSpec <TModel> > specs) where TModel : class { if (worksheet == null) { throw new ArgumentNullException(nameof(worksheet)); } var ensuredSpecs = EnsureSpecs(specs); var map = new Dictionary <string, CellToPropertyMap>(); var properties = _propertiesExtractor.GetPublicProperties <TModel>(); var headerRow = worksheet.FirstRowUsed(); var mappingExceptions = new List <MappingException>(); foreach (var property in properties) { try { var cell = FindMatchingCell(property, headerRow, ensuredSpecs); if (cell.AnyValue()) { var cellMap = new CellToPropertyMap(property, cell.ColumnLetter, cell.RowNumber, cell.ToString()); map.Add(property.Name, cellMap); } } catch (MappingException exception) { LogFailedToMapProperty(property, exception); mappingExceptions.Add(exception); } } if (mappingExceptions.Any()) { throw new MappingException($"'{mappingExceptions.Count}' mapping issues found.", mappingExceptions); } return(map); }