def getColour():
bgr = (238,66,240)
xv = '%02x%02x%02x' % bgr
iv = int(xv,16)
return iv
r= sheet.usedRange # 选定单元格区域
#设置字体
r.Font.ThemeColor = 4 # 颜色主题 设置字体色
r.Font.ColorIndex = 22 # 颜色索引 设置字体色
r.Font.Color = getColour() # 通过RGB得到颜色整数,设置字体颜色
#设置单元格
r.Interior.ThemeColor = 4 # 颜色主题 设置背景色
r.Interior.ColorIndex = 22 # 颜色索引 设置背景色
r.Interior.Pattern = 1 # 设置填充为纯色
r.Interior.TintAndShade = -0.350000 # 颜色的深浅度
r.Interior.Color = getColour() # 通过RGB获得颜色整数,设置背景色
颜色索引表
![](https://img-blog.csdnimg.cn/img_convert/ab2da16ca77d8dc709bdd5c0c2da1381.png)