private bool GetQualityCotrols(FileInfo file, string attribute) { try { var excel = new LinqToExcel.ExcelQueryFactory(file.ToString()); var columnsNames = excel.GetColumnNames(excel.GetWorksheetNames().ToList().First()).ToList(); foreach (var item in excel.GetWorksheetNames().ToList()) { foreach (LinqToExcel.Row r in excel.Worksheet(item).ToList()) { var enumerator = r.GetEnumerator(); while (enumerator.MoveNext()) { if (string.IsNullOrEmpty(enumerator.Current.Value.ToString())) { enumerator.MoveNext(); continue; } var coded = enumerator.Current.Value.ToString(); GetIdRemarkLabel remarkId = GetIdRemarkLabelBL.GetIdRemarkLabel(columnsNames[r.IndexOf(enumerator.Current)]); enumerator.MoveNext(); SetClientsCatalogsNextelBL.SetClientsCatalogsNextel(attribute, remarkId.IDRemarkLabel, coded, enumerator.Current.Value.ToString()); } } } return(true); } catch (Exception) { return(false); } }
public IEnumerable <TModel> ParseExcelFile <TModel>(string fileName, ref string errorMsg) { var excelFile = new LinqToExcel.ExcelQueryFactory(fileName); IEnumerable <string> workSheetNames = excelFile.GetWorksheetNames(); IEnumerable <TModel> sheetData = new List <TModel>(); foreach (string sheetName in workSheetNames) { List <string> excelHeaders = excelFile.GetColumnNames(sheetName).ToList(); List <string> props = typeof(TModel).GetProperties().Select(x => x.Name).ToList(); bool isSubset = !excelHeaders.Except(props).Any(); if (isSubset) { errorMsg = ""; var data = from row in excelFile.Worksheet <TModel>(sheetName) select row; sheetData = data.AsEnumerable(); } } return(sheetData); }