I need to output a table and each cell will have a different background colour depending on the value. The ranges might be something like 0-25 will have a red background, 26-50 orange, 51-75 yellow and 76-100 green.
My template is a word document and if I set the cell colour to red and then look at the xml I get the following:
<w:tcPr>
<w:tcW w:w="3081" w:type="dxa"/>
<w:shd w:val="clear" w:fill="FF0000" w:color="auto"/>
</w:tcPr>
<w:p w:rsidR="0092058F" w:rsidRDefault="0057272B" w:rsidP="007D2CAD">
<w:pPr>
<w:jc w:val="right"/>
</w:pPr>
<w:r w:rsidRPr="0057272B">
<w:t>[onload;att=w:shd#w:fill=[x.bgcolour]][x.m1]</w:t>
</w:r>
</w:p>
As you can see I am trying to update the value of w:fill with the value stored in x.bgcolour. On merge I get a corrupt document. When I look at the merged xml it looks like this (where the value of x.bgcolour is 00ff30).
<w:shd w:val="clear" w:color="auto" w:fill="FF0000" w:fill=00ff30=""/>
The original fill colour is still there (FF0000), and the new value is outside of the quotation marks. I feel like I'm close to getting it right. What do I need to do to make this work? Thanks!
According to your snippet, the [onload] TBS fields will be moved into the entity w:shd
and the attribute named w:fill=[x.bgcolour]
. Which is wrong.
What you need is simply to move the TBS field [x.bgcolour].
It can be done with something like this :
<w:tcPr>
<w:tcW w:w="3081" w:type="dxa"/>
<w:shd w:val="clear" w:fill="FF0000" w:color="auto"/>
</w:tcPr>
<w:p w:rsidR="0092058F" w:rsidRDefault="0057272B" w:rsidP="007D2CAD">
<w:pPr>
<w:jc w:val="right"/>
</w:pPr>
<w:r w:rsidRPr="0057272B">
<w:t>[x.bgcolour;att=w:shd#w:fill][x.m1]</w:t>
</w:r>
</w:p>