Forum


Replies: 12   Views: 356
Column removal
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  · 05-06-2024 - 13:21

Hello,

The following sample code uses tables.docx (file available in the package: examples/files/docxpath folder) to remove the cell that contains "22":

$docx = new CreateDocxFromTemplate('tables.docx');

$referenceNode = array(
    'customQuery' => '//w:tr/w:tc[contains(., "22")]',
);
$docx->removeWordContent($referenceNode);

$docx->createDocx('output_table');

If you run this code using the included file, you can check the cell is removed from the DOCX output.

If we replace in this same file "22" with "${sipcol_removal}" and run:

$docx = new CreateDocxFromTemplate('tables.docx');

$referenceNode = array(
    'customQuery' => '//w:tr/w:tc[contains(., "${sipcol_removal}")]',
);
$docx->removeWordContent($referenceNode);

$docx->createDocx('output_table');

The cell is removed correctly too. We recommend you check and run these samples using the file included in the package. Also note that XPath is case sensitive by default (https://www.phpdocx.com/documentation/snippets/case-insensitive-xpath).

For further support, we'd need to check the DOCX file you are using. Please open a support ticket (https://www.phpdocx.com/support) and attach the DOCX document you are using, we'll generate a sample using it.

Regards.