Replies: 7   Views: 2437
Replacevariablebytext on wordfragment
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 skicka.spam.hit  · 02-10-2017 - 17:26


Is there anyway to use ReplaceVariableByText on a WordFragment? The WordFragment in question is created by the addExternalFile function. The reason for this weird setup is that this seems to be the only way to make list paragraphs to "restart" and not "continue numbering" (i.e. creating a addExternalFile form a file with the list paragraphs "restarted" and adding this to the document). 

Posted by admin  · 03-10-2017 - 07:44


You can use the replaceVariableByText method after the WordFragment has been added. But the addExternalFile method uses an altChunk tag; these external files aren't transformed to MS Word format but added as external files, so you can't 'manipulate' their contents.

We recommend using embedHTML to add HTML and mergeDOCX to merge DOCX documents; using both methods you get MS Word contents that can be changed. If you need to merge other document formats, they can be transformed to DOCX using the conversion plugin.

If you need to change styles or tags on the fly you can use DOCXPath or DOCXCustomizer.



Posted by skicka.spam.hit  · 03-10-2017 - 20:26

Thanks! We have come quite far in our project and phpdocx seems to fit our purposes quite well, this I think being the only outstanding issue before launching (and perhaps evaluating which license to purchase..).

The thing really is that we need to be able to "restart numbering" when using the same paragraph style over and over in different parts of the document which is being created. My previous post suggested a rather(?) complicated way, but that seemed as the only working method so far. 

So, is there perhaps an easier way to restart numbering? The document looks/should look something like.


Some text in normal paragraph style.

(a) some text

(b) some further text

Some further text in normal paragraph style.

(a) this should be (a) and not (c).

(b) this should be (b) and not (d)."



Posted by admin  · 04-10-2017 - 06:29


How are you adding the lists into the document? If you are using the addList method, phpdocx 7.5 released yesterday added a new option (numId) to control restart and continue numbering; you can use a common paragraph style and a unique numId to restart numbering.

If you need to change this property on existing elements on the fly you can use DOCXPath or DOCXCustomizer.


Posted by skicka.spam.hit  · 04-10-2017 - 07:59

Ideally, we would like to add the "list" as paragraphs, not lists. Thus, so far we have added them using the addText function setting the pStyle to "aParagraphListNumber" (as the style happens to be named in our system/docs). Perhaps there are not so many setbacks of using addList and a list style instead of addText and a paragraph style?

Posted by admin  · 04-10-2017 - 08:27


MS Word uses the same tag for lists and paragraphs, but it adds some internal tags to set lists. We recommend you using the methods available to work with lists; as there's no special tag to restart a numbering but using other numId.


Posted by skicka.spam.hit  · 04-10-2017 - 08:41

However the addList will not allow for multilist? Would like the user (post the document being created) to be able to go to a specific list-item, hit tab and thereby have the item indented and "named" for instance (i) which is the sub-level of the (a),(b),(c)etc-list/paragraph. 

Posted by admin  · 04-10-2017 - 10:20


Lists support the same properties than paragraphs so you shouldn't find any issue to accomplish what you need.

The addList method allows to add multiple levels, set custom list styles or import styles from external DOCX.

Sorry but the support included for the trial package is limited to general questions and doubts. If you purchase a license the dev team can generate a custom script to show how to accomplish it in detail (we recommend you to purchase an Advanced or Premium license to be able to use DOCXPath to ease what you need to do).