Excel can use an integer calculated by the formula Red + (Green * 256) + (Blue * 256 * 256)
def rgbToInt(rgb):
colorInt = rgb[0] + (rgb[1] * 256) + (rgb[2] * 256 * 256)
return colorInt
ws.Cells(row,col).Font.Color = rgbToInt((255,255,128))
for i in range(2,5): # Assuming there is Cell(D2)=1, Cell(D3)=0, Cell(D4)=-1
cell = ws.Cells(i,4)
if cell.Value < 0:
cell.Interior.Color = rgbToInt((255,0,0)) # red
elif cell.Value == 0:
cell.Interior.Color = rgbToInt((211,211,211)) # grey
elif cell.Value > 0:
cell.Interior.Color = rgbToInt((0,255,0)) # green
else:
print('Error.')
https://stackoverflow.com/questions/55287232/how-to-change-excel-cell-color-according-to-value