Forum


Replies: 7   Views: 1325
Insert link with the same formatting like common text
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 admin  · 09-05-2021 - 08:14

Hello,

The replaceVariableByText method keeps existing styles when replacing placeholders.

Using the replaceVariableByWordFragment method, If the styles are applied to the paragraph (w:pPr styles), when you do an inline replacement the existing styles remain, but if the styles are applied to the placeholder (w:rPr styles), then replacing the placeholder by a WordFragment the styles will be changed to use the styles from the WordFragment. Premium licenses include options to keep and mix existing styles when replacing a placeholder in complex replacements, for example replaceVariableByHTML includes the stylesReplacementType option:

stylesReplacementType     string   Empty as default. Only available in Premium licenses.

* usePlaceholderStyles: keeps placeholder styles, styles from the imported HTML are ignored. Applies to the following styles: pPr, rPr.

* mixPlaceholderStyles: mixes placeholder styles, placeholder styles overwrite HTML styles with the same name. Applies to the following styles: pPr, rPr.

Since phpdocx 9, Advanced and Premium licenses also include getWordStyles. This method can be used for example to get existing styles from a placeholder and apply them to the WordFragment to be added.

We recommend you to upgrade to the latest Premium version, so you can do complex replacements to mix and keep styles when replacing placeholders by HTML and WordFragments.

Regards.