I'm not 100% certain that this would work, but theoretically it should solve the issue you're facing. From the python-docx
documentation:
- The
CharacterStyle
class has attributes base_style
and font
. - Since the
base_style
object points to another CharacterStyle
instance (or None), you can make a "nested" query until you find a font
color.
It would look something like
style = run.stylewhile style: if style.font.color.rgb: color = style.font.color.rgb break else: style = style.base_style
Answered 2 years ago
Luna Ella
I'm not 100% certain that this would work, but theoretically it should solve the issue you're facing. From the
python-docx
documentation:- The
- Since the
It would look something likeCharacterStyle
class has attributesbase_style
andfont
.base_style
object points to anotherCharacterStyle
instance (or None), you can make a "nested" query until you find afont
color.style = run.stylewhile style: if style.font.color.rgb: color = style.font.color.rgb break else: style = style.base_style