public void ReadExcel() { try { using (var package = new ExcelPackage(AccessFilesOnOneDrive.GetFile())) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; int rowCount = worksheet.Dimension.Rows; int сolCount = worksheet.Dimension.Columns; var rawText = string.Empty; for (int row = 1; row <= rowCount; row++) { for (int col = 1; col <= сolCount; col++) { rawText += worksheet.Cells[row, col].Value.ToString() + "\t"; } rawText += "\n"; } Console.WriteLine(rawText); } } catch (Exception ex) { logger.Error(ex.Message); } }
public HashSet <string> CompareColumnsAndGetUnique(int FirstColumn, int SecondColumn) { var source = new HashSet <string>(); var comparer = new HashSet <string>(); try { using (ExcelPackage package = new ExcelPackage(AccessFilesOnOneDrive.GetFile())) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; int rowCaunt = 1; while (worksheet.Cells[rowCaunt, 2].Value != null) { source.Add(worksheet.Cells[rowCaunt, 2].Value.ToString()); rowCaunt++; } rowCaunt = 1; while (worksheet.Cells[rowCaunt, 3].Value != null) { comparer.Add(worksheet.Cells[rowCaunt, 3].Value.ToString()); rowCaunt++; } } } catch (Exception ex) { logger.Error(ex.Message); } var _unique = new HashSet <string>(source); _unique.UnionWith(comparer); var duplicate = new HashSet <string>(source); duplicate.IntersectWith(comparer); _unique.ExceptWith(duplicate); return(_unique); }