当前位置: 动力学知识库 > 问答 > 编程问答 >

Python Excel color tint

问题描述:

Ciao guys,

I am making a simple Python script which reads .xlsx file and generates moin wiki table. I have some problems with applying tint to excel colors.

I used this as a reference -> https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.foregroundcolor(v=office.15).aspx

Here is what I have so far:

HLSMAX = 255

def applyNewTint(r, g, b, tint):

hls = colorsys.rgb_to_hls(r, g, b)

h = hls[0]

l = hls[1]

s = hls[2]

print( 'tint = ' + str(tint) )

print( 'h = ' + str(h) )

print( 'l = ' + str(l) )

print( 's = ' + str(s) )

if tint > 0:

l = l * (1.0 - tint) + (HLSMAX - HLSMAX * (1.0 - tint))

if tint < 0:

l = l * (1.0 + tint)

print('l2 = ' + str(l))

print(str(colorsys.hls_to_rgb(h, l, s)))

return colorsys.hls_to_rgb(h, l, s)

Works OK for tint < 0.0

r = 79

g = 129

b = 189

tint = -0.499984740745262

h = 0.5909090909090908

l = 134.0

s = -0.41353383458646614

l2 = 67.00204474013489

(39.70796608819941, 64.52076486268622, 94.29612339207037)

But if I try tint > 0.0, it gives me this messed up rgb (values higher than 255)

r = 79

g = 129

b = 189

tint = 0.5999938962981048

h = 0.5909090909090908

l = 134.0

s = -0.41353383458646614

l2 = 206.59926145207072

(121.57701047565052, 198.86996590875984, 291.6215124284909)

Do you guys have any idea of what I am doing wrong?

分享给朋友:
您可能感兴趣的文章:
随机阅读: