Find duplicate value in excel using c# with epplus library ?
Find duplicate value in excel using c#:
in this post I want to check whether there are any duplicate values present in an excel file using c# code. Is there any code snippet which can help me find duplicate values using c# ? this is possible by the given code try it .
public static bool HasDuplicates(string path)
{
List<object> allObjects = new List<object>();
using (ExcelPackage excel = new
ExcelPackage(new FileInfo(path)))
{
foreach (var sheet in excel.Workbook.
Worksheets)
{
// Go through all cells
foreach (var cell in sheet.Cells)
{
// Ignore null cells
if(cell.Value != null)
{
if (allObjects.Contains(cell.Value))
return true;
allObjects.Add(cell.Value);
}
}
}
return false;
}
}
Comments
Post a Comment