CYL
CYL

Reputation: 1

Can I change word font color using python?

I am using docxtpl to dealing with word template. Using RichText can change the new add font, but I want to change font color that exist in word template. Is there any solution?

Upvotes: 0

Views: 311

Answers (1)

p_sutherland
p_sutherland

Reputation: 491

You can change the font to your desired color directly to the expression in your template document.

So, say the expression you want to render in color is {{website}} and the value is 'stack overflow' you can set the font of the expression in the Word Template: enter image description here

And in your code create the context and render it:

template = DocxTemplate(path_to_template)
context = {'website':"stack overflow"}
template.render(context)
template.save(path_to_output_file)

And the output is in color: enter image description here

Upvotes: 0

Related Questions