Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>setValue expects the second parameter to be a plain string. It's not possible to provide a section object. </p> <p>I've dived into the code and there's not an easy way to have a section object returning a value that could be used by the setValue function.</p> <p>As I had the same issue, I've wrote a patch for the Template.php file that allows you to clone table rows before replacing their tags with setValue. Each row gets an unique id, allowing you to identify the template tags for each different row.</p> <p>This is how it works:</p> <p>Add this function to your Template.php file (found inside the PHPWord directory)</p> <pre><code>public function cloneRow($search, $numberOfClones) { if(substr($search, 0, 2) !== '${' &amp;&amp; substr($search, -1) !== '}') { $search = '${'.$search.'}'; } $tagPos = strpos($this-&gt;_documentXML, $search); $rowStartPos = strrpos($this-&gt;_documentXML, "&lt;w:tr", ((strlen($this-&gt;_documentXML) - $tagPos) * -1)); $rowEndPos = strpos($this-&gt;_documentXML, "&lt;/w:tr&gt;", $tagPos) + 7; $result = substr($this-&gt;_documentXML, 0, $rowStartPos); $xmlRow = substr($this-&gt;_documentXML, $rowStartPos, ($rowEndPos - $rowStartPos)); for ($i = 1; $i &lt;= $numberOfClones; $i++) { $result .= preg_replace('/\$\{(.*?)\}/','\${\\1#'.$i.'}', $xmlRow); } $result .= substr($this-&gt;_documentXML, $rowEndPos); $this-&gt;_documentXML = $result; } </code></pre> <p>In your template file add to each table one row that you will use as a template row. Let's assume you've added a tag ${first_name} in this row.</p> <p>To get a table with 3 rows call: $document->cloneRow('first_name', 3);</p> <p>The working copy of your template is now updated with a table containing 3 rows. Each tag inside the row has been appended with a # and row number.</p> <p>To set your values, use setValue $document->setValue('first_name#1', 'Name on the first row'); $document->setValue('first_name#2', 'Name on the second row'); $document->setValue('first_name#3', 'Name on the third row');</p> <p>I hope this is useful! I'll keep an updated version of the code and documentation here: <a href="http://jeroen.is/phpword-templates-with-repeating-rows/" rel="noreferrer">http://jeroen.is/phpword-templates-with-repeating-rows/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload