6

I am working with python docx and here I am stuck.

from docx import Document
document = Document()
run = document.add_paragraph().add_run()
font = run.font
from docx.shared import RGBColor
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)

This generate RGB(66, 36, 233) when viewed from microsoft word.

how can I get RGBColor(0x42, 0x24, 0xE9) type color given RGB(66, 36, 233) format ?

Rahul
  • 10,830
  • 4
  • 53
  • 88
  • 1
    Question still remains but using `font.color.rgb = RGBColor(255, 000, 000)` works just fine. – Rahul Nov 10 '16 at 05:49

1 Answers1

5

The three parameters to RGBColor are just integers, so:

RGBColor(66, 36, 233)

Produces the same results as:

RGBColor(0x42, 0x24, 0xE9)

The 0x prefix is just a way of telling Python that what follows is to be interpreted as a base-16 number. It doesn't have to do with python-docx per se; any way you get an integer between 0 and 255 into those three positions will work fine.

scanny
  • 26,423
  • 5
  • 54
  • 80