private static bool ContainsObject(ExcelData data) { foreach (var item in datas) { if (item.name == data.name) { return(true); } } return(false); }
private static void ReadExcelFile(string file) { Common.Utility.File.RecursionFileExecute(file, EXCEL_FILE_SUFFIX, (filePath) => { using (FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs)) { DataSet result = excelReader.AsDataSet(); foreach (System.Data.DataTable item in result.Tables) { ExcelData excelData = new ExcelData(item); if (ContainsObject(excelData)) { throw new System.Exception(string.Format("[{0}] excel data is already exist.", excelData.name)); } datas.Add(excelData); } } } }); }