2015-10-06 55 views
0

我正在用PHPWord處理一些報告生成模塊。我從服務器加載模板文檔文件。如果數據庫中有數據,我需要將動態行添加到表中。如果數據庫中沒有數據,我想從已加載的模板文件中刪除表。有沒有辦法使用phpword從加載的模板文件中刪除表?如何通過在PHPWord中操作模板來刪除表格

回答

0

您應該能夠通過表格四周包裹一個塊,然後用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); 
} 
相關問題