Skip to content
本页内容

Top10 (对象)

代表条件格式规则的前十项。通过对某一区域应用颜色,有助于查看相对于其他单元格的单元格的值。

说明

所有条件格式设置对象都包含在 FormatConditions 集合对象中,该对象是 Range 集合的子对象。

可以使用 FormatConditions 集合的 AddAddTop10 方法创建前 10 个格式规则。

示例

python
#本示例通过条件格式规则生成一个动态数据集并对前 10 个值应用颜色
def test():
    #Building data
    Application.Range("A1").Value2 = "Name"
    Application.Range("B1").Value2 = "Number"
    Application.Range("A2").Value2 = "Agent1"
    Application.Range("A2").AutoFill(Application.Range("A2:A26"), xlFillDefault)
    Application.Range("B2:B26").FormulaArray = "=INT(RAND()*101)"
    Application.Range("B2:B26").Select()

    #Applying Conditional Formatting Top 10
    Application.Selection.FormatConditions.AddTop10()
    Application.Selection.FormatConditions.Item(Application.Selection.FormatConditions.Count).SetFirstPriority()
    top = Application.Selection.FormatConditions.Item(1)
    top.TopBottom = xlTop10Top
    top.Rank = 10
    top.Percent = False

    #Applying color fill
    font = Application.Selection.FormatConditions.Item(1).Font
    font.Color = RGB(0, 155, 115)
    font.TintAndShade = 0
    interior = Application.Selection.FormatConditions.Item(1).Interior
    interior.PatternColorIndex = xlAutomatic
    interior.Color = RGB(5, 185, 115)
    interior.TintAndShade = 0
python
#本示例设置第一张工作表上区域 E1:E10 中第一个(Top10)条件格式的TopBottom属性,并将该条件格式设置为按百分比值确定排位,然后设置该条件格式的排位值的百分比
def test():
    top = Worksheets.Item(1).Range("E1:E10").FormatConditions.Item(1)
    top.TopBottom = xlTop10Bottom
    top.Percent = True
    top.Rank = 20