Replies: 6   Views: 4672
Replace table variable
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by neiron  · 31-05-2016 - 08:52

Can I make a table ?

Those. values in cells through affix substitutes, but in some areas is the union of cells, both vertically and horizontally

Posted by admin  · 31-05-2016 - 09:33


Yes, phpdocx allows to do tables such as the indicated. You could do that using the embedHtml method or templates.


Posted by neiron  · 31-05-2016 - 11:37

I need to use the templates as It planned that the user will create a template and specify which fields he wants in the table. 

Example table (template docx-file):

|___$val1$___|___$val2$___|___ $val3$___|


$docx = new CreateDocxFromTemplate('../../files/TemplateSimpleTable.docx');
$data = array(
                'val1' => '1',
                'val2' => '2',   
                'val3' => '3',            
                'val1' => '4',
                'val2' => '5',   
                'val3' => '6',            
                'val1' => '7',
                'val2' => '8',   
                'val3' => '9',            
$docx->replaceTableVariable($data, array('parseLineBreaks' => true));

The number of rows I do not know in advance. Those. is N-lines. Then he will go again connected cells, then again a lot of lines, etc.


Posted by admin  · 31-05-2016 - 15:53


What license and version of phpdocx are you using?


Posted by General research Computer Center  · 01-06-2016 - 08:12

Neiron my colleague. We use Pro version 5.5

It is clear that we can automatically generate a table. But we need to get the user himself can define a template for the table, he needed columns and styles for them.

Posted by admin  · 01-06-2016 - 09:29


The method replaceTableVariable allows to add any values in a table; but it doesn't allow to add values then a header in the same table then values again... and so on.

You'll need to generated distinct tables for each set of values or generate the tables dynamically (using addTable or embedHtml or replaceVariableByHTML).

The next version of phpdocx will include, only for Corporate and Enterprise licenses, a new class called DOCXPATH that will ease tasks that the one you need.