Forum


Replies: 1   Views: 101
How to remove specific table cell? or table row?

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.