문제

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?

도움이 되었습니까?

해결책

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']
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top