我正在尝试找出如何使用EPPLUS excel库中的条件格式突出显示给定列中的重复值。在可用的验证类型列表中,我看不到重复的值相关类型。这里的想法是,一列有多个值,但其中一些值是重复的。因此,我希望应用类似于手动步骤的格式设置,即选择列(或区域),转到条件格式-突出显示单元格规则-复制值。然后基本上任何副本都会被分配一个浅红色的填充颜色。或者,如果我可以使用一个新的规则类型,公式similar =COUNTIF($B3:$B$3,$B3)>1,它可以应用于整个范围。但是如何使用EPPLUS添加新的规则类型作为条件格式?欢迎任何建议,想法。我没有发布代码,因为我没有做任何能捕捉到逻辑的东西。
发布于 2020-10-20 01:11:43
在经历了一些试验和错误之后,我设法让它工作起来。下面的示例代码希望这能帮助寻找相同信息的人。
'Enable Automatic Calc mode on the excel workbook
p.Workbook.CalcMode = ExcelCalcMode.Automatic
'Add Conditional formatting for the given range
Dim cfRange As ExcelAddress = New ExcelAddress("B3:B" & ValToRow.ToString)
Dim cfRule = ws.ConditionalFormatting.AddDuplicateValues(cfRange)
cfRule.Style.Fill.PatternType = ExcelFillStyle.Solid
cfRule.StopIfTrue = False
cfRule.Style.Fill.BackgroundColor.Color = ColorTranslator.FromHtml("#F8696B") 'red color
'The Pattern Type and color can be set or ignored as it may affect readability of cell values.
' Uncomment to change and use as desired
'cfRule.Style.Fill.PatternType = ExcelFillStyle.LightHorizontal
'cfRule.Style.Fill.PatternColor.Color = Color.WhiteSmoke
'Add this line after above code.
ws.calculate()https://stackoverflow.com/questions/64431428
复制相似问题