简体   繁体   中英

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

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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM