Forum


Replies: 1   Views: 285
How to remove specific table cell? or 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  · 08-04-2024 - 15:30

Hello,

To remove a row or a cell, you can use table-row and table-cell types or use a custom XPath query.
In the following sample included in the package: DocxPath/removeWordContent/sample_9.php you can find a sample removing a row using a customQuery.

Using types, please check the following samples that use the tables.docx file included in the package.

Remove the row that contains "14":

$docx = new CreateDocxFromTemplate('../../files/docxpath/tables.docx');

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

$docx->removeWordContent($referenceNode);

Remove the cell that contains "14":

$docx = new CreateDocxFromTemplate('../../files/docxpath/tables.docx');

// get the reference node to be removed
$referenceNode = array(
    'type' => 'table-cell',
    'parent' => '/',
    'contains' => 14,
);

$docx->removeWordContent($referenceNode);

If instead of the whole cell you want to remove only the contents, you should use a custom XPath query to select only the elements in the cell.

Regards.