Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Friday, March 3, 2017

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;
    }
}

No comments:

Post a Comment