Replies: 1   Views: 2280
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 InnovativeP  · 03-11-2018 - 01:23

Hi and thanks for any tips in advance.


Depending on the selctions made by the User, a number of template docx are selected and then merged into a single document before being used in a createfromtemplate scenario.

I tried the sample code which works well with the docs to be merged hardcoded in.

However, given that the docs to be merged will vary in quantity I need a dynamic way to achieve this.

Attempted Solutions

I have tried creating an array of the template docx with the following code:

$this->merge->mergeDocx($path . 'tCoverPage.docx', $listComponets, $path .'template.docx', array('mergeType' => 0));

and also createing a string like this:

$a = implode($listComponents, '","');
$b = '"' . $a . '"';
$this->merge->mergeDocx($path . 'tCoverPage.docx', array($b), $path .'template.docx', array('mergeType' => 0));

and neither seem to work. I know its not a problem with PHPDOCX as the sample work.

Am I using the merge function incorrectly or is there another way to dynamically change which documents are merged.

Thanks in anticipation of any assistance.


Posted by admin  · 04-11-2018 - 10:15


We recommend you to check if the following code:

$a = implode($listComponents, '","');
$b = '"' . $a . '"';

is returning an array with multiple values or an array with a single string value. We also recommend you to follow the PHP documentation about arrays ( or use a function such as array_push (

Each value of the documentArray option ( must be an existing DOCX file (Advanced or Premium licenses) or a DOCXStructure object when working with in-memory DOCX document using a Premium license.