How to highlight duplicates in a specific column in Excel worksheet in .NET

How can we highlight duplicates in a specific column. I just want to highlight like excel does with light red color and not remove the duplicates.

@sourav24,
You can highlight duplicates with conditional formatting as the following code:

Workbook book = new Workbook();
Worksheet ws = book.Worksheets[0];
//Create a cell area A1:A100, you may extend it accordingly
CellArea area;
area.StartColumn = 0;
area.EndColumn = 0;
area.StartRow = 0;
area.EndRow = 99;
int index = ws.ConditionalFormattings.Add();
FormatConditionCollection fcs = ws.ConditionalFormattings[index];
fcs.AddArea(area);
int conditionIndex = fcs.AddCondition(FormatConditionType.Expression, OperatorType.None, “= AND(COUNTIF($A$1:$A$100, A1)> 1,NOT(ISBLANK(A1)))”, “”);
FormatCondition fc = fcs[conditionIndex];
fc.Style.Font.Color = Color.Yellow;
fc.Style.BackgroundColor = Color.Red;
fc.Style.Pattern = BackgroundType.Solid;
book.Save(“outvalidationconditionalresult.xlsx”);