https://packagist.org/packages/phpoffice/phpword
composer require phpoffice/phpword
composer require phpoffice/phpword:dev-master
https://github.com/PHPOffice/PHPWord
https://phpword.readthedocs.io/en/latest/templates-processing.html

word文字替换
<?php
namespace app\index\controller;
//引入TemplateProcessor
use PhpOffice\PhpWord\TemplateProcessor;
class Index
{
public function index()
{
//实例化, 参数传入模板文件地址
$templateProcessor = new TemplateProcessor('static/jianding.docx');
//替换(设置)变量值,我在测试的时候替换的字符比较长,这里缩短了
$templateProcessor->setValue('ketiname','测试题目');
$templateProcessor->setValue('ketifuzeren','测试题目');
$templateProcessor->setValue('suozaidanwei','测试题目');
$templateProcessor->setValue('tianbiaoriqi','测试题目');
//保存文件
$templateProcessor->saveAs('static/jianding1.docx');
}
}

文字替换实现代码

内容模版