Excel 2007 conditional formatting - how to get cell color?

后端 未结 7 1236
别那么骄傲
别那么骄傲 2020-12-06 02:17

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 forma

相关标签:
7条回答
  • 2020-12-06 02:46

    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!

    0 讨论(0)
提交回复
热议问题