Forum


Replies: 2   Views: 2681
How to insert cross-reference at a specific place
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  · 25-07-2018 - 04:58

I tried setting up a wordML with the following:

$wordML = '<w:r><w:fldChar w:fldCharType="begin"/></w:r>';
$wordML .= '<w:r><w:instrText xml:space="preserve">' . 'REF ' . $crossRefName . '</w:instrText></w:r>';
$wordML .= '<w:r><w:fldChar w:fldCharType="separate"/></w:r>';
$wordML .= '<w:r><w:t>' . $crossRefText . '</w:t></w:r>';
$wordML .= '<w:r><w:fldChar w:fldCharType="end"/></w:r>';

$bookmarkId = rand(9999999, 999999999);
$wordML .= '<w:bookmarkStart w:id="' . $bookmarkId . '" w:name="_GoBack"/>';
$wordML .= '<w:bookmarkEnd w:id="' . $bookmarkId . '"/>';

And then: 

$docx->replaceVariableByWordML(['myVar' => $wordML]);

But when opening the generated document I get the following error:

The Open XML file 'test.docx' cannot be opened because there are problems with the content or the file name might contain invalid characters. Unspecified error | Location: 2.

Where do you think the definition of my wordML is wrong?