Forum


Replies: 2   Views: 182
Removewordcontent with type table-row
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  · 20-08-2024 - 12:20

Hello,

By default, the parent element of DOCXPath queries is the main document body (w:body) (unless a customQuery is used). If you want to query by any parent you need to set "/" as parent:

Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).

From the sample DocxPath/removeWordContent/sample_9.php included in the package:

// get the reference node to be removed
$referenceNode = array(
    'type' => 'table-row',
    'parent' => '/',
    'occurrence' => 2,
);

// a custom query can also be used for more complex tasks
/*
$referenceNode = array(
    'customQuery' => '//w:tbl/w:tr[2]',
);
*/

$docx->removeWordContent($referenceNode);

Please try the following code with your DOCX:

$referenceNode = array(
    'type' => 'table-row',
    'parent' => '/',
    'contains' => 'Bravo',
);

$docx->removeWordContent($referenceNode);

Regards.