How to color text to later be put in a docx file?
<p>I want to color a text present in the string and pass the string to another python file so that to put received colored string into a docx file. I tried in this way but it is not working.</p>

<pre><code>from termcolor import colored
from docx import Document

document = Document()
item_i="\n\n Comma is required in line dependent clause is in beginning\n\n" 
ctxt = colored(item_i, 'blue')
p=document.add_paragraph()
p.add_run(ctxt)
document.add_page_break()

document.save('demo.docx')
</code></pre>

<p>it displays properly in terminal but not in file, it shows an error</p>

<pre><code>from termcolor import colored

item_i="\n\n Comma is required in line dependent clause is in beginning\n\n" 
ctxt = colored(item_i, 'blue')
print ctxt
</code></pre>

<p>In this format it displays properly. Kindly help me to resolve this issue.</p>

<p>You should be using <code>docx</code>'s text formatting since, as Jacques de Hooge said, <code>termcolor</code> is for terminal. See <a href="http://python-docx.readthedocs.io/en/latest/user/text.html#apply-character-formatting" rel="nofollow">here</a>.</p>

<pre><code>from docx.shared import RGBColor
</code></pre>

<p>Then</p>

<pre><code>run = p.add_run(item_i)
run.font.color.rgb = RGBColor(0x00, 0x00, 0xFF)
</code></pre>

python python-2.7 python-docx termcolor