如何在PHPWord中通过操作模板删除表
我正在使用PHPWord开发一些报告生成模块。我从服务器加载了一个模板文档文件。若数据库中有可用的数据,我需要向表中添加动态行。如果数据库中没有数据,我想从加载的模板文件中删除表。是否有任何方法可以使用phpword从加载的模板文件中删除表 您应该能够通过在表周围包装一个模板块并使用cloneBlock函数来实现这一点:如何在PHPWord中通过操作模板删除表,php,phpword,Php,Phpword,我正在使用PHPWord开发一些报告生成模块。我从服务器加载了一个模板文档文件。若数据库中有可用的数据,我需要向表中添加动态行。如果数据库中没有数据,我想从加载的模板文件中删除表。是否有任何方法可以使用phpword从加载的模板文件中删除表 您应该能够通过在表周围包装一个模板块并使用cloneBlock函数来实现这一点: if ('there-is-data-to-be-added') { // show the template table normally $template
if ('there-is-data-to-be-added')
{
// show the template table normally
$templateProcessor->cloneBlock('TABLE-WRAP', 1);
// clone your row(s) with your data
$templateProcessor->cloneRow('ROW-TEMPLATE', 10);
// add your data to the cloned rows...
}
else
{
// hide the table (note that deleteBlock function doesn't seem to work when you have other template fields inside the table)
$templateProcess->cloneBlock('TABLE-WRAP', 0);
}