Excel 2007条件格式 - 如何获取单元格颜色? [英] Excel 2007 conditional formatting - how to get cell color?
问题描述
ABC
1 -1 1 1
2 -1 0 0
3 0 0 1
现在我选择了以下范围,并使用条件格式化(使用默认的红色黄色绿色颜色标度)格式化....现在范围颜色变为
ABC
1绿色红色红色
2绿色黄色黄色
3黄色黄色红色
现在我想询问范围内任何单元格的颜色,例如MsgBox Range(A1)。Interior.Color
但是它不会说它是绿色的,为什么?你可以帮助我吗?
范围(A1)。Interior.Color总是返回16777215
范围(A1)。Interior.ColorIndex总是返回-4142
(无论A1的颜色是红,蓝,绿,...)
Range(A1,C3)。FormatConditions.Count
这个总是返回0,为什么?
p>因为我可能有一个以上三种不同的颜色...我没有找到任何好的方法来处理这个条件格式的默认颜色...我这样做了。那么每当我问单元格的颜色时,我都会检索正确的颜色!
for(int t = 0; t < d_distinct.Length; t ++)
{
Excel.FormatCondition cond =
(Excel.FormatCondition)range.FormatConditions.Add(
Excel.XlFormatConditionType.xlCellValue,
Excel .XlFormatConditionOperator.xlEqual,
=+ d_distinct [t],
mis,mis,mis,mis,mis);
cond.Interior.PatternColorIndex =
Excel.Constants.xlAutomatic;
cond.Interior.TintAndShade = 0;
cond.Interior.Color = ColorTranslator.ToWin32(c [t]);
cond.StopIfTrue = false;
}
d_distinct保存一个范围内的所有不同的值... c是一个颜色[]它为每个不同的值拥有不同的颜色!这个代码很容易被翻译成vb!
Let's assume i have the following range from (a1:c3)
A B C
1 -1 1 1
2 -1 0 0
3 0 0 1
Now i have selected the following range, and formatted it using Conditional Formatting (using default red yellow green color scale).... now range colors became
A B C
1 Green Red Red
2 Green Yellow Yellow
3 Yellow Yellow Red
Now I want to ask the color of any cell in the range, for example MsgBox Range("A1").Interior.Color but it does not say that it is Green, why? Plz can you help me?
Range("A1").Interior.Color always returns 16777215 Range("A1").Interior.ColorIndex always returns -4142
(no matter whether the color of A1 is red, blue, green, ...)
Range("A1", "C3").FormatConditions.Count this one returns always 0, why?
since i may have more than three different colors in a time... i didn't find any good way of handling this with conditional formatting's default colors... i did it this way. then whenever i ask the color of the cell, i retrieve the correct color!
for (int t = 0; t < d_distinct.Length; t++ )
{
Excel.FormatCondition cond =
(Excel.FormatCondition)range.FormatConditions.Add(
Excel.XlFormatConditionType.xlCellValue,
Excel.XlFormatConditionOperator.xlEqual,
"="+d_distinct[t],
mis, mis, mis, mis, mis);
cond.Interior.PatternColorIndex =
Excel.Constants.xlAutomatic;
cond.Interior.TintAndShade = 0;
cond.Interior.Color = ColorTranslator.ToWin32(c[t]);
cond.StopIfTrue = false;
}
d_distinct holds all the distinct values in a range... c is a Color[] which holds distinct colors for every distinct value! this code can easily be translated to vb!
这篇关于Excel 2007条件格式 - 如何获取单元格颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!