OpenTBS:如何动态更改表中的行颜色 [英] OpenTBS: How to dynamically change color of rows in a table
问题描述
我在docx文件中使用以下行的表:
[b.num; block = w:tr]
[b.name]
在PHP中,我使用 $ TBS-> MergeBlock('b',$ data_1);
,其添加来自 $ data_1
数组的内容。
$ b
问题是,如何动态控制每行的文本颜色,例如
1)使用条件区段
为此,为每种可能性使用一行:
[b.num; block = w:tr; [b.name]'='John'](red)[b.name]
[b.num; block = w:tr; default] code>
2)使用参数att更改颜色
当您对文本的部分应用颜色时,内部XML如下:
< w:p>
< w:r>
< w:rPr>
< w:color w:val =FF0000/>
< / w:rPr>
< w:t>此文字为红色< / w:t>
< / w:r>
< / w:p>
因此,您可以通过在模板中应用任何颜色来准备单元格,然后使用字段用参数att调整颜色的值。
[b.num; block = w:tr]
[b.name]
[b.name; att = w:color#w:val; if [val] ='John'; then'FF0000'; else'548DD4']
I use a table in docx file with the following rows:
[b.num;block=w:tr]
[b.name]
In PHP, I use $TBS->MergeBlock('b', $data_1);
which adds the content from the $data_1
array.
The question is, how can I dynamically control the text color in each row, e.g. if the name is "John", then mark it in red, otherwise use blue?
Thanks in advance!
I can suggest two solutions.
1) use conditional sections
For this, use one row for each possibility:
[b.num;block=w:tr;when '[b.name]'='John'] (red) [b.name]
[b.num;block=w:tr;default] (blue) [b.name]
2) change the color using parameter "att"
In the celle of the row, when you apply a color to a part d the text, the inner XML is like this:
<w:p>
<w:r>
<w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t>this text is red</w:t>
</w:r>
</w:p>
So you can prepare the cell by applying a apply any color in the template, and then use a field with parameter "att" to turn the value of the color.
[b.num;block=w:tr]
[b.name]
[b.name;att=w:color#w:val;if [val]='John';then 'FF0000';else '548DD4']
这篇关于OpenTBS:如何动态更改表中的行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!