1

使用下面的代码,我能够使用使用后期绑定的 VB.net 应用程序检测 Excel 中单元格的内部颜色。问题是,如果单元格具有条件格式,我无法检测到使用此代码的条件格式应用的内部颜色的变化

  Dim x = objSheets.range("J" & RowCount).Interior.ColorIndex

如果是条件格式的结果,是否可以确定内部颜色?请问我该怎么做?

谢谢

4

2 回答 2

0

您必须实例化一个 FormatCondition 对象并执行以下操作

FormatCondition format =(FormatCondition)( targetSheet.get_Range("D1:E10",
                Type.Missing).FormatConditions.Add(XlFormatConditionType.xlExpression, XlFormatConditionOperator.xlEqual,
                "=$D1=$E1", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));

            format.Font.Bold = true;
            format.Font.Color = 0x000000FF;

详情: http ://www.techques.com/question/1-10240132/Conditional-Formatting-in-Excel-with-C

于 2013-10-09T03:26:08.403 回答
0

经过进一步研究,我遇到了这个问题:不幸的是,如果将条件格式应用于单元格,则 Range 的 Color 和 ColorIndex 属性不会返回显示的单元格的颜色。它也不允许您确定条件格式当前是否对单元格有效。除非有人知道如何做到这一点,否则我将不得不编写代码来复制条件格式。

于 2013-12-20T00:44:33.203 回答