Replies: 1   Views: 3371
Removing all content from a template when working with createdocxfromtemplate
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 hannorahn  · 22-02-2016 - 11:26

In my application a user can upload a word template and we generate a report using the uploaded template (using CreateDocxFromTemplate($file)).

Now I need to clear all the content from the template.

How can this be accomplished?

Posted by admin  · 22-02-2016 - 14:55


We recommend you to don't overwrite the template. Phpdocx doesn't change the original template unless you overwrite it.

For example, this code:

$docx = new CreateDocxFromTemplate('TemplateSimpleText.docx');

$first = 'PHPDocX';
$variables = array('FIRSTTEXT' => $first);
$docx->replaceVariableByText($variables, $options);


generates a new DOCX file, output.docx, without changing the template.