擅长:python、mysql、java
<p>您需要添加如下参数end\ U color:</p>
<pre><code>fill = PatternFill(start_color='538DD5',end_color='538DD5',fill_type='solid')
</code></pre>
<p>检查此链接:<a href="https://openpyxl.readthedocs.io/en/stable/formatting.html" rel="nofollow noreferrer">https://openpyxl.readthedocs.io/en/stable/formatting.html</a></p>
<pre><code>from openpyxl import Workbook
from openpyxl.styles import PatternFill
from openpyxl.formatting.rule import CellIsRule
wb = Workbook()
ws = wb.active
ws['B2'] = -2
ws['B3'] = -1
ws['B4'] = 0
ws['C2'] = -1
ws['C3'] = 0
ws['C4'] = 1
fill = PatternFill(start_color='538DD5',end_color='538DD5',fill_type='solid')
#print(fill)
ws.conditional_formatting.add('B2:C4', CellIsRule(operator='lessThan', formula=[0], fill=fill))
wb.save('mwe.xlsx')
wb.close()
</code></pre>
<p>结果:</p>
<p><a href="https://i.stack.imgur.com/asIkN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/asIkN.png" alt="enter image description here"/></a></p>