How To Get Actual Color Of Text In MS Word When Python-docx Returns None

Asked 2 years ago
Answer 1
Viewed 276
0

I'm not 100% certain that this would work, but theoretically it should solve the issue you're facing. From the python-docx documentation:

  1. The CharacterStyle class has attributes base_style and font.
  2. 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 EllaLuna Ella