Skip to content
本页内容

ColorIndex (属性)

返回或设置一个 Any 值,它代表字体的颜色。

说明

颜色可指定为当前调色板中颜色的索引值,也可指定为下列 XlColorIndex 常量之一:

  • xlColorIndexAutomatic
  • xlColorIndexNone

示例

python
#本示例将 Sheet1 上 A1 单元格的字体颜色更改为红色
def test():
    Application.Worksheets.Item("Sheet1").Range("A1").Font.ColorIndex = 3
python
#此示例判断D3单元格的字体颜色是否为自动配色,不是则设置字体颜色为绿色
def test():
    font = Application.Worksheets.Item("Sheet1").Range("D3").Font
    if font.ColorIndex == xlColorIndexAutomatic:
        print("字体颜色为自动配色")
    else:
        font.ColorIndex = 4