/// <summary> /// Reads consumption-compilant portions of Data from the underlaying data-source /// </summary> /// <returns>an IEnumerable of the base-set</returns> protected override IEnumerable <IBasicKeyValueProvider> ReadData() { IWorkbook book = OpenWorkbook(sourceFile); bool foundSheet = false; for (int i = 0; i < book.NumberOfSheets; i++) { string msg; ISheet sheet = book.GetSheetAt(i); if ((ImportWorkSheetDecider.Decide(sheet.SheetName, DecisionMethod.Simple, out msg) & (DecisionResult.Acceptable | DecisionResult.Success)) != DecisionResult.None) { foundSheet = true; yield return (new DictionaryWrapper(new Dictionary <string, object> { { "SheetName", sheet.SheetName } })); foreach (IRow row in sheet) { if (row != null) { Dictionary <string, object> vals = new Dictionary <string, object>(); foreach (ICell cell in row.Cells) { XLNumber num = cell.ColumnIndex; object value = GetCellValue(cell, cell.CellType); if (value != null) { vals.Add(num.ToString(), value); } } string origin = $"{sheet.SheetName}::{row.RowNum}"; vals.Add("$origin", origin); yield return(new DictionaryWrapper(vals)); } } } } if (!foundSheet) { LogParserEvent(null, $@"No sheet has met the configured Constraints. Settings for sheet-search: {ImportWorkSheetDecider}", ParserEventSeverity.Warning, null); } }
/// <summary> /// Reads consumption-compilant portions of Data from the underlaying data-source /// </summary> /// <returns>an IEnumerable of the base-set</returns> protected override IEnumerable <IDictionary <string, ExcelDataRecord> > ReadData() { IWorkbook book = OpenWorkbook(sourceFile); bool foundSheet = false; for (int i = 0; i < book.NumberOfSheets; i++) { string msg; ISheet sheet = book.GetSheetAt(i); if ((ImportWorkSheetDecider.Decide(sheet.SheetName, DecisionMethod.Simple, out msg) & (DecisionResult.Acceptable | DecisionResult.Success)) != DecisionResult.None) { foundSheet = true; yield return (new Dictionary <string, ExcelDataRecord> { { "SheetName", new ExcelDataRecord { FormattedText = sheet.SheetName, RawData = sheet.SheetName } } }); DataFormatter f = new DataFormatter(); foreach (IRow row in sheet) { if (row != null) { Dictionary <string, ExcelDataRecord> vals = new Dictionary <string, ExcelDataRecord>(); foreach (ICell cell in row.Cells) { XLNumber num = cell.ColumnIndex; object value = GetCellValue(cell, cell.CellType); if (value != null) { vals.Add(num.ToString(), new ExcelDataRecord { RawData = value, FormattedText = f.FormatCellValue(cell) }); } else if (readNullData) { vals.Add(num.ToString(), new ExcelDataRecord { RawData = null, FormattedText = "" }); } } string origin = $"{sheet.SheetName}::{row.RowNum}"; vals.Add("$origin", new ExcelDataRecord { FormattedText = origin, RawData = origin }); yield return(vals); } } } } if (!foundSheet) { LogParserEvent(null, $@"No sheet has met the configured Constraints. Settings for sheet-search: {ImportWorkSheetDecider}", ParserEventSeverity.Warning, null); } }