0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vigour
  • 45
  • 1
  • 8

1 Answers1

2

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']
Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Trying to use the first method, but it doesn't work. Should the (red) and (blue) tags be written as you specified, or the text has to be marked in those colors, without the tags? Thanks for the info! – vigour Oct 06 '13 at 18:12
  • The text has to be marked in those colore. But you can also leave the text for testing. In the first solution they are two sections in the block. One of the section will be selected by TBS for display. – Skrol29 Oct 08 '13 at 07:52