Forum


Replies: 3   Views: 1781
Dynamic text of crossreferences
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 dev@ams  · 27-02-2020 - 13:22

We are trying to add crossreferences using html extended with your latest beta. How can we make the text of the cross reference dynamic. It refers to a bookmark in the document and we want it to follow the bookmark name, also when the generated document is opened in Word and the bookmark text changes. The text of the cross reference should change with that. Is that possible? And if yes, could you provide an example snippet? 

 

Posted by dev@ams  · 27-02-2020 - 15:02

Thank you very much for your reply! Do you have an example of how we can make it work for headers?

Posted by admin  · 27-02-2020 - 15:19

Hello,

The example Core/addPageNumber/sample_1.php adds a page number that is updated automatically when the DOCX opens. If you try to do the same in the body you need to update it manually; you can read this explained on the API page:

https://www.phpdocx.com/api-documentation/word-content/insert-page-number-Word-document-with-PHP

If the page number is not added to a header or footer the user may need to press F9 in the MS Word interface to update its value to the current page.

In our previous reply, we meant that other fields, such as page number, are updated automatically when they are added to headers or footers, but this doesn't happen in all cases. This is a limitation from MS Word and we can't avoid it.

We recommend you to use a macro to update fields automatically:

https://groups.google.com/forum/#!topic/microsoft.public.word.numbering/yUNIqiEvjLw

http://www.gmayor.com/installing_macro.htm

There're events that can run macros automatically such as AutoOpen; on the previous page you can read more information about these events.

Regards.