public int Import(string filename) { try { IList <Person> persons = new List <Person>(); var file = new FileInfo(filename); using (var package = new ExcelPackage(file)) { var worksheet = package.Workbook.Worksheets.FirstOrDefault(); if (worksheet != null) { if (OldAddressbookWorksheet.IsOldAddressbookExcel(worksheet)) { persons = ImportOldAddressbookExcel(worksheet); _logger.Info(LoggerMessage.GetFunctionUsageMessage("Import Old Addressbook")); } else { persons = ImportAddressbookExcel(worksheet); _logger.Info(LoggerMessage.GetFunctionUsageMessage("Import Addressbook")); } SavePersons(persons); } } return(persons.Count); } catch (Exception e) { _logger.Warn(e, "Exception on Import Persons"); throw; } }
private IList <Person> ImportOldAddressbookExcel(ExcelWorksheet worksheet) { var oldWorksheet = new OldAddressbookWorksheet(worksheet); return(oldWorksheet.ImportPersons()); }