如何使用openpyxl对特定的Excel单元进行颜色填充? [英] How do I color-fill in a specific Excel cell using openpyxl?

查看:1421
本文介绍了如何使用openpyxl对特定的Excel单元进行颜色填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 openpyxl 来修改特定的excel单元格。我可以很容易地修改字体样式,只需要:

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?

我尝试探索其他一些东西,如 PatternFill ,但是我无法准确地得到我的 m寻找。所有我需要的是改变单个单元格的填充颜色。

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.

推荐答案

什么是 PatternFill 您尝试使用的代码?是否与此类似?

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

或分级:

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

这篇关于如何使用openpyxl对特定的Excel单元进行颜色填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆