Forum


Replies: 3   Views: 331
Delete entire table if no data
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  · 07-12-2021 - 17:36

Hello,

The best approach is using removeWordContent included in DOCXPath. This method allows removing contents, for example a whole table. You can generate a code to remove a table according to its contents, position, attributes and other queries. In the package you can find many samples using DOCXPath methods. If you know in your code if a table will filled with data or not, you can use replaceTableVariable or any other method to add the new data and use removeWordContent to remove those tables that won't be needed.

removeTemplateVariable removes a single placeholder and deleteTemplateBlock is designed to work with block of contents instead of a single content (https://www.phpdocx.com/documentation/practical/blocks). Although deleteTemplateBlock can work with single contents, removeWordContent is a better approach.

Regards.