0
我正在嘗試將工作腳本寫入Excel中,以便將excel寫入excel。我不得不格式化列的大小和類型,但是我需要其中一列有條件顏色。
ex./ A列有百分比。 對於所有細胞< 0%,我們所需要的細胞是紅色 對於所有細胞= 0%,我們所需要的細胞是黃 對於所有細胞> 0%,我們所需要的細胞是綠色python中的條件背景顏色 - python中的新增功能
而且那麼,每列的第一行需要是藍色的。
我發現腳本類似,但它們不是有條件的。
我試過的
# Light red fill.
format1 = name.add_format({'bg_color': '#FFC7CE'})
# Light yellow fill.
format2 = name.add_format({'bg_color': '#FFEB9C'})
# Green fill.
format3 = name.add_format({'bg_color': '#C6EFCE'})
try:
sheet1.conditional_format('A:A', {'type': 'cell',
'criteria': '<',
'value': 0,
'format': format1})
sheet1.conditional_format('A:A', {'type': 'cell',
'criteria': '==',
'value': 0,
'format': format2})
sheet1.conditional_format('A:A', {'type': 'cell',
'criteria': '>',
'value': 0,
'format': format3})
except AttributeError:
sheet1.conditional_format = None
except TypeError:
type = None
有一些變化,但不會改變顏色
,我已經試過的
while 'BU:BU' != " " :
if 'BU:BU' < '0%':
sheet1.style = redFill
elif 'BU:BU' == '0%':
sheet1.style = yellowFill
elif 'BU:BU' > '0%':
sheet1.style = '#C6EFCE'
else:
pass
continue
有一些變化,但是,保持陷入無限循環。
謝謝