Forum


Replies: 5   Views: 5230
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,

Posted by snowpowa  · 11-04-2013 - 12:12

That's sad if it doesn't support multiple templates. :(

Posted by dataassociates  · 11-04-2013 - 12:12

Did you get any response here?

Posted by admin  · 11-04-2013 - 12:12

Hello,

A next version of phpdocx will include template merge feature. We're testing merging and is working really fine but we need to do more testing before releasing.
We're working with a new HTML to DOCX converter that has a lot of new features.

Regards.

Posted by nicolas  · 11-04-2013 - 12:12

Hi,

Indeed, PHPDOCX 2.3 can insert DOCX document inside another:
[code]$docx->addDOCX('../files/Text.docx');[/code]

However, it is not possible to add a DOCX template inside the DOCX document that we are developping :'(
I tried :
[code]
$docx = new CreateDocx();
$docx->setEncodeUTF8();
$docx->addText(’First content’);
$docx->addDOCX('template_test.docx');
$docx->addTemplateVariable('VAR1', 'value1');
$docx->addTemplateVariable('VAR2', 'value2');
$docx->addTemplateVariable('VAR3', 'Value3);
$docx->addText(’Second content’);[/code]
but the template variables are not replaced.

I also tried:
[code]
$docx = new CreateDocx();
$docx->setEncodeUTF8();
$docx->addText(’First content’);
$docx->addTemplate('template_test.docx');
$docx->addTemplateVariable('VAR1', 'value1');
$docx->addTemplateVariable('VAR2', 'value2');
$docx->addTemplateVariable('VAR3', 'Value3);
$docx->addText(’Second content’);[/code]

The template variables are well replaced but only the DOCX template is present in the current DOCX document we are developping...

Any help would be appreciated