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  · 20-05-2024 - 11:23

Hello,

You can use DOCXPath methods for this task. With getWordContents you can get the text contents of the chosen element (such as specific cell); then using removeWordContent you can remove specific elements.

To remove columns in a table you need to remove the cells (w:tc tag) of the rows (w:tr tag) in the specific position (1, 2...). In this case you need to use a custom XPath query. In the examples/DocxPath folder available in Advanced and Premium packages you can find many samples using all DOCXPath methods.

For example, the following sample removes the second column using the tables.docx file incuded in the package:

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

$referenceNode = array(
    'customQuery' => '//w:tbl[1]/w:tr/w:tc[2]',
);
$docx->removeWordContent($referenceNode);

Regards.