套用樣版會讓OUTPUT更理想、而不用自己調整文件元件。官方有一個 sample 教學與檔案(Sample_07_TemplateCloneRow.docx)
1.如果要加上圖片到 docx 中,圖檔的目錄是相對於本程式的相對路徑。
2.寫法可參考:(資料來源)
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('templatefile.docx');
$templateProcessor->setImageValue('foto', array('path' => 'dummy_foto.jpg', 'width' => 100, 'height' => 100, 'ratio' => true));
$templateProcessor->saveAs('result.docx');
但是 setImageValue 只能傳入 3 個參數,如果想讓圖片(文字)在表格裡居中對齊,請將 sample 檔案製作完美。
3.可參考 TAD 的文件:https://campus-xoops.tn.edu.tw/modules/tad_book3/page.php?tbsn=36&tbdsn=1340