python-docx表格单元格加颜色,python docx设置表格单元格背景和文本颜色

使用python-docx库创建表格时,可以根据条件改变单元格的背景色和文字颜色。示例代码展示了如何根据预定义样式修改单元格样式,但直接应用样式无效。正确的做法是通过插入XML元素来设置特定单元格的填充颜色,如RGB颜色1F5C8B。每个单元格需要单独创建并添加颜色设置元素。
摘要由CSDN通过智能技术生成

I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.

I could not find any usefull resources about single cell formatting

Any suggestions?

Edit 1

my code

style_footer = "DarkList"

style_red = "ColorfulList"

style_yellow = "LightShading"

style_green = "MediumShading2-Accent6"

style_transperent = "TableNormal"

for a,rec in enumerate(data):

#V headinh se piše prvo polje iz table heada

document.add_heading(rec['tableHead'][0][0], level=1)

image_path = imageFolder + "\\" + slike[a]

document.add_picture(image_path, height=Inches(3.5))

#y += 28

#worksheet.insert_image( y, 1,imageFolder + 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值