I am working on some report generation module with PHPWord. I load a template document file from server. I need to add dynamic row to a table if data is available in database. If there is no data in the database i wants to remove table from loaded template file. Is there any way to remove table from a loaded template file using phpword?
答案 0 :(得分:1)
您应该能够通过在表格周围包装模板块并使用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);
}