Replies: 3   Views: 898
Add custom attributes while adding content
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 Brightalley  · 25-08-2021 - 09:05

Is it possible to add customAttributes while adding content instead of using the customizeWordContent function after adding content? 

Something like:

$docx->addText($text, ['customAttributes' => ['id' => 'myCustomId']]);


Posted by admin  · 25-08-2021 - 09:54


There's no way to add custom attributes using methods such as addText or addTable. Please note that each internal OOXML attribute may have its own scope, options and others. And adding not valid OOXML attributes may generate a corrupted document that MS Word can't open.

The only way would be using DOCXPath or DOCXCustomizer.


Posted by Brightalley  · 25-08-2021 - 14:34

Thank you.
In addition, although it seems possible to add not valid OOXML attributes with customizeWordContent(), after editing and saving in MS Word these attributes are removed so that they can no longer be used when reading the document. I'm going to use a different approach.

Posted by admin  · 26-08-2021 - 05:39


As alternative approach you could use bookmarks, that allow setting custon names.