Forum


Replies: 5   Views: 5092
Merge documents and/or templates
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 nicolas  · 26-04-2011 - 22:14

Hi,

First, thanks for this API, it is so usefull :)
However, an important function isn't present. Indeed, we can not merge templates. For instance, the following code only import the last template in the document generated by the API:

[code]<?php

require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addTemplate('template1.docx');
$docx->addTemplateVariable('var1', 'value1');

$docx->addTemplate('template2.docx');
$docx->addTemplateVariable('var2', 'value2');

$docx->createDocx('testdoc.docx');

?>[/code]

Is there a solution to merge templates or add text after (or before) a template ?

[code]<?php

require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addTemplate('template1.docx');
$docx->addTemplateVariable('var1', 'value1');

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
'officia deserunt mollit anim id est laborum.';

$paramsText = array(
'b' => 'single',
'font' => 'Arial'
);

$docx->addText($text, $paramsText);

$docx->createDocx('testdoc.docx');

?>[/code]

Only the template is generated, not the text.

Best regards,