python-docx-template icon indicating copy to clipboard operation
python-docx-template copied to clipboard

Dynamically set cellbg

Open SergeyZaykov opened this issue 2 years ago • 0 comments

##Is your feature request related to a problem? Please describe. I wanted to set dynamically cellbg, like this {% if x > 2 %}{% cellbg 'FFFFFF' %}{% endif%}. But it doesn't work. Here was recomended to use a variable in {% cellbg %} and define its value during rendering (at python side). For nested JSON arrays this solution is tedious. IMHO, the better way is defining cell's colour in a Word document directly.

Describe the solution you'd like

{% cellbg 'ff0000' if x > 1 else 'ffffff' %}cell's text

Describe alternatives you've considered

For setting background colour dynamicaly used Jinja If Expression It is no way set cell's background colour if condition is true only. You need to define background colour in both cases.

Additional context

The 'classic' white colour is 'ffffff'.

SergeyZaykov avatar Mar 08 '22 07:03 SergeyZaykov