0
我正在用PHPWord处理一些报告生成模块。我从服务器加载模板文档文件。如果数据库中有数据,我需要将动态行添加到表中。如果数据库中没有数据,我想从已加载的模板文件中删除表。有没有办法使用phpword从加载的模板文件中删除表?如何通过在PHPWord中操作模板来删除表格
我正在用PHPWord处理一些报告生成模块。我从服务器加载模板文档文件。如果数据库中有数据,我需要将动态行添加到表中。如果数据库中没有数据,我想从已加载的模板文件中删除表。有没有办法使用phpword从加载的模板文件中删除表?如何通过在PHPWord中操作模板来删除表格
您应该能够通过表格四周包裹一个块,然后用cloneBlock函数来实现这一目标:
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);
}