Forum


Replies: 4   Views: 1211
How to delete row to table, to get variable in document
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 admin  · 07-07-2021 - 14:57

Hello,

The customQuery option allows using a custom XPath query (https://www.w3schools.com/xml/xpath_intro.asp). If you know a text content available in a table row you can use the contains function available in XPath, instead of setting the position. For example, using a DOCX document included in the package, you can remove the row that includes 24 running:

$referenceNode = array(
    'customQuery' => '//w:tbl/w:tr[contains(.,"24")]',
);

$docx->removeWordContent($referenceNode);

You can also get DOCXPath query information using the following method: getDocxPathQueryInfo. DOCXPath and XPath includes many options to choose the contents to be changed, updated, removed, cloned, inserted...

Please note that XPath has some protected characters that you may need to escape if you want to query by a text with protected characters.

If you open a support ticket (https://www.phpdocx.com/support) attaching the DOCX you want to modify, the dev team will generate a custom code using your template.

Regards.