我需要输出一个表格,每个单元格都会有不同的背景颜色,具体取决于值。范围可能类似于 0-25 将具有红色背景、26-50 橙色、51-75 黄色和 76-100 绿色。
我的模板是一个word文档,如果我将单元格颜色设置为红色,然后查看xml,我会得到以下内容:
<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>
如您所见,我正在尝试使用存储在 x.bgcolor 中的值更新 w:fill 的值。在合并时,我得到一个损坏的文档。当我查看合并的 xml 时,它看起来像这样(其中 x.bgcolor 的值为 00ff30)。
<w:shd w:val="clear" w:color="auto" w:fill="FF0000" w:fill=00ff30=""/>
原始填充颜色仍然存在 (FF0000),并且新值在引号之外。我觉得我快要做对了。我需要做什么才能完成这项工作?谢谢!
根据您的代码段,[onload] TBS 字段将被移动到实体w:shd
和名为 w:fill=[x.bgcolour]
的属性中。这是错误的。
您只需要移动TBS字段[x.bgcolor]。
可以用这样的事情来完成:
<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>