Forum


Replies: 1   Views: 2750
Replacevariablebyexternalfile() and styles
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 afantini  · 26-04-2018 - 13:52

Using replaceVariableByExternalFile() I find that the text loses all the formatting styles used in the external file, being all formatted with the "normal" style: this, of course, despite the same styles are also present in the template.

Am I making a mistake?How can this be remedied?

Thank you.

Posted by admin  · 26-04-2018 - 14:23

Hello,

That method uses altChunk tags, that are only supported by MS Word 2007 or newer on Windows. This way of adding external files is handled by MS Word, although you can set matchSource as true (https://www.phpdocx.com/api-documentation/templates/replace-variable-external-file-Word-document) some styles won't keep.

If you are adding HTML, we recommend you to use native methods that transform HTML to Word:

https://www.phpdocx.com/api-documentation/word-content/embed-html-Word-document-with-PHP

https://www.phpdocx.com/api-documentation/templates/replace-variable-html-Word-document

If you need to add DOCX documents, you can use the mergeDocx method to keep content and styles:

https://www.phpdocx.com/api-documentation/docxutilities/merge-Word-documents-with-PHP

Regards.