C# 如何创建;文本中包含“;使用C为Excel设置格式条件(格式条件)#

C# 如何创建;文本中包含“;使用C为Excel设置格式条件(格式条件)#,c#,excel,conditional-formatting,C#,Excel,Conditional Formatting,我想要的是能够根据Excel文件中的文本值更改某些单元格的颜色 以下是我所拥有的: private void validator(Excel.Worksheet sheet, int lastCellRowNum, XlRgbColor color) { FormatCondition cond = sheet.get_Range("A1:I"+lastCellRowNum,Type.Missing).FormatConditions.Add(XlFormatConditionType.xl

我想要的是能够根据Excel文件中的文本值更改某些单元格的颜色

以下是我所拥有的:

private void validator(Excel.Worksheet sheet, int lastCellRowNum, XlRgbColor color)
{
  FormatCondition cond = sheet.get_Range("A1:I"+lastCellRowNum,Type.Missing).FormatConditions.Add(XlFormatConditionType.xlCellValue, XlFormatConditionOperator.xlEqual, sheet.Cells[1,1]);
  cond.Interior.Color = color;
}
此代码将单元格[1,1]的精确值与其他值进行比较,而不仅仅是包含的一段字符串

基本上,我想要的是一种允许“Contains”条件改善代码性能的格式。例如,如果单元格[1,1].Value2中的值为“Hello”,则我希望将值为2等于“ByeHelloBye”的任何单元格或包含“Hello”的任何其他字符串包含在条件中

现在我必须调用这个方法30次以上,因为我不知道如何创建这个条件。将所有格式应用于70000行需要35秒。太多了

我的问题的其他可能解决方案是:

  • 将整个二维颜色数组传递给Excel

  • 对我的英语感到抱歉,并提前表示感谢。

    因此,一位朋友找到了这个可怕问题的答案。允许这种“包含”格式的函数实际上存在。这是如何做到的:

     FormatCondition cond = sheet.get_Range("A1:I70000", Type.Missing).FormatConditions.Add(XlFormatConditionType.xlTextString, Type.Missing, Type.Missing, Type.Missing, "SomethingToFilterIfContained", XlContainsOperator.xlContains, Type.Missing, Type.Missing);
     cond.Interior.Color = color;
    

    我希望这对某人有所帮助。

    一年后,尽管我做了很多搜索,但你的问题/答案是我找到的唯一对我有帮助的结果!!非常感谢你!!我很高兴我帮助了你。我记得找到这个的噩梦。