我需要以编程方式使用条件格式在 Excel 工作表中查找重复值。
试过这种方式,但在 6 行代码中我有 COM 异常
无法转换为 Excel.FormatCondition
这是我的代码
Excel.Workbook xlWB = Application.ActiveWorkbook;
Excel.Worksheet xlWS = xlWB.ActiveSheet;
xlWS.Range["B2:B9"].Select();
Excel.Range xlS = Application.Selection;
xlS.FormatConditions.AddUniqueValues();
Excel.FormatCondition xlFC =
(Excel.FormatCondition)xlS.FormatConditions[xlS.FormatConditions.Count];
xlFC.SetFirstPriority();
Excel.FormatCondition xlFC1 = (Excel.FormatCondition)xlS.FormatConditions[1];
xlFC1.Interior.Pattern = Excel.XlPattern.xlPatternAutomatic;
xlFC1.Interior.TintAndShade = 0;
xlFC1.Interior.Color = ColorTranslator.FromOle(13551615);