Replies: 2   Views: 1036
Is it possible to change entire color occurances from a template document?
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 Diaa  · 04-08-2021 - 12:06


I was wondering if there's a possibility to change the entire occurances of a specific color in a template document to the document I'm producing? for example I want to change the entire occurances of the color #FF0000 to #00FF00, whether it's set as a background color, text or paragraph color, border color.. etc

Posted by admin  · 04-08-2021 - 14:23


There's no method to change all occurrences of a specific color in all targets: background, custom styles, default styles, contents... You need to use a set of methods: setBackgroundColor, setDocumentDefaultStyles, customizeWordContent.

If the color value to be changed is very specific and you are sure it won't appear in contents you don't want to replace, you can use rawSearchAndReplace that allows replacing specific text strings in all XML files of a DOCX.