Replies: 2   Views: 3197
Templates new line with shift-enter
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 rjonge  · 23-11-2011 - 14:35


i've got a problem with new lines in templates.

In my template (made in word) I can use 'Enter' for a new paragraph. This works fine when I include a template in phpdoc with the addTemplate() method. I can generate a good docx file.

But Word also allows you to create a new line within a paragraph. To do this, don't press Enter. Instead, press Shift-Enter. Phpdocx create a corrupt document when I use a template with a 'Shift-Enter' in it WITH a registered variabele. It wil generate fine, if I use a non existing variabele or no variabele at all.

for example:

Hi $name$ this is a test

Hi $name2$ this is a test

New lines in both templates are done with Shift-Enter. Only difference between templates is variabele name ($name$ vs $name2$)

[b]PHP code:[/b]
$oDocx = new CreateDocx();
$oDocx ->addTemplate('./template1.docx');
$oDocx ->addTemplateVariable('name', 'Roy');
$oDocx ->createDocx('sample')
* This wont't work with template1. It generates a corrupt file. Variable 'name' should be replaced in template.

But the next code will work fine.
$oDocx = new CreateDocx();
$oDocx ->addTemplate('./template2.docx');
$oDocx ->addTemplateVariable('name', 'Roy');
$oDocx ->createDocx('sample')
* template 2 has 'name2' variabele. But only 'name' is registered. So 'name2' is not replaced. This works fine. But in the generated docx file i still got $name2$ of course. But it opens fine without an error.

Of course I want a working situation for template1. Many of our customers uses Shift-Enter in their document with template variabeles. (for example their adress over a few lines)

[b]Word error message is:[/b]
The file sample.docx cannot be opened because there are problems with the contents
--> details: Unspecified error. Location: Part: /word/document.xml, line 2, column: 0

Has anybody a solution?

Posted by rblanken  · 11-04-2013 - 12:13

Some issue here, any solution ?