How do I color-fill in a specific Excel cell using openpyxl?

。_饼干妹妹 提交于 2019-12-21 17:48:10

问题


I'm currently using openpyxl to modify specific excel cells. I am able to modify font styles very easily, simply just:

ws['A1'].font = Font(color=colors.White)

But I am unable to change the fill of the specific cell. Anyone know any documentation about how to do this? I want to just change the color of one cell, so what other packages are required?

I tried exploring some other things like PatternFill, but I haven't been able to accurately get what I'm looking for. All I need is to change the fill color of a single cell.


回答1:


What was the PatternFill code that you tried using? Is it something similar to this?

from openpyxl.styles import PatternFill

redFill = PatternFill(start_color='FFEE1111', end_color='FFEE1111', fill_type='solid')

Then to apply to a specific cell use:

ws['A1'].fill = redFill

Or for grading:

fill = PatternFill(fill_type=None, start_color='FFFFFFFF', end_color='FF000000')


来源:https://stackoverflow.com/questions/30904765/how-do-i-color-fill-in-a-specific-excel-cell-using-openpyxl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!