怎么通过python docx设置word单元格颜色

我想要达到的结果

我通过python docx来设置word的表格,在遇到某个单元格里面的值比较特殊的时候,想将此单元格设置成红色,不知道怎么才能实现?

文章:利用Python docx修改word关键词颜色 中也许有你想要的答案,请看下吧

设置单元格颜色:

from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml

shading_elm_1 = parse_xml(r'<w:shd {} w:fill="1F5C8B"/>'.format(nsdecls('w')))
table.rows[0].cells[0]._tc.get_or_add_tcPr().append(shading_elm_1)