Forum


Replies: 8   Views: 3426
Update document cross-references
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 arnaudbouchard  · 28-06-2018 - 02:36

Hi there,

Imagine I have a document with bullet points :

  • Item 1, see more in chapter 2.1
  • Item 2, see more in chapter 2.2
  • Item 3, see more in chapter 2.3

Further in the document, each chapter is surrounded by BLOCK_ placeholders. In the list above, each chapter number (2.x) is a cross-reference to the corresponding chapter. Is there a way for the cross-references to be updated if a block (chapter) is deleted? Manually in Word you would right-click the cross-reference and select "Update field", or select the whole doc (ctrl+a), right-click and "Update field".

Thanks,

Posted by admin  · 28-06-2018 - 06:54

Hello,

You could change or remove it using DOCXPath (https://www.phpdocx.com/documentation/introduction/docxpath) doing a query by it's content.

Regards.

Posted by arnaudbouchard  · 01-07-2018 - 23:43

Thanks for the suggestion but I don't really see how you would do it. Is that the only way?

Posted by admin  · 02-07-2018 - 11:29

Hello,

You could also generate a macro and autorun it when the DOCX is open.

Regards.

Posted by arnaudbouchard  · 03-07-2018 - 04:32

Is it possible to trigger a macro via phpdocx?

Posted by admin  · 03-07-2018 - 06:22

Hello,

No, phpdocx can't run MS Word macros. The library only can add macros from external files or keep the existing ones in a template.

Regards.

Posted by arnaudbouchard  · 01-08-2018 - 04:40

I'll rephrase my question. Imagine I have a doc looking like this:

My cross-reference to "Third sub-title" is: 1.c

1.      First title
    a.  First sub-title
~BLOCK_testBlock~
    b.  Second sub-title
~BLOCK_testBlock~
    c.  Third sub-title
2.      Second title
3.      Third title

Now, let's imagine I remove 1.b programmaticaly.

With DOCXPath as you suggest, how can I change my cross-reference from 1.c to 1.b? I managed to do it if the cross reference text is set to "Paragraph text" via the getWordContents() function. But getting the list style / numbering seems difficult.

Thanks,

Posted by admin  · 01-08-2018 - 06:16

Hello,

There's no method or option to get the numbering value of a list item, as it's set dinamically when the DOCX is open. Maybe you could use addLink with an internal bookmark (https://www.phpdocx.com/api-documentation/word-content/insert-link-Word-document-with-PHP), adding a fixed string. But to change a bookmark value of a link dinamically you may need to use DOCXCustomizer (https://www.phpdocx.com/documentation/introduction/docxcustomizer) that is only available in Premium licenses.

Regards.

 

Posted by bdm  · 01-08-2018 - 06:44

I used embedHTML() function to achieve this. Manipulating array automatically update links too connected to array's key. Create an array of your chapters, loop your bullet points based on that array. But I guess we have a different scenario.