原文地址:http://www.niu12.com/article/16
php使用phpword將word內容變量替換
a.安裝phpword
composer require phpoffice/phpword
b.當前目錄下a.docx,假設word內容需要替換的變量為
說明人:${user}
電話:${email}
c.php改寫word內容
<?php
// 根據模板生成用戶信息word
$templateProcessor = new TemplateProcessor("./a.docx");
$templateProcessor->setValue('user', '周起');
$templateProcessor->setValue('email', '445864742@qq.com');
$templateProcessor->saveAs("./b.docx");