phpword替换word里边的变量
composer安装phpword
执行composer require phpoffice/phpword命令
D:\phpstudy_pro\WWW\manager-system>composer require phpoffice/phpword
Using version ^0.17.0 for phpoffice/phpword
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
– Installing pclzip/pclzip (2.8.2): Downloading (100%)
– Installing phpoffice/common (0.2.9): Downloading (100%)
– Installing zendframework/zend-escaper (2.6.1): Downloading (100%)
– Installing phpoffice/phpword (0.17.0): Downloading (100%)
phpoffice/phpword suggests installing ext-gd2 (Allows adding images)
phpoffice/phpword suggests installing ext-xsl (Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template)
phpoffice/phpword suggests installing dompdf/dompdf (Allows writing PDF)
Writing lock file
Generating autoload files
composer.json文件添加以下内容:
“phpoffice/phpword”: “^0.17.0”
word模板
tp5中替换word中的变量
public function test2(){ vendor('phpoffice.phpword'); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(ROOT_PATH.'public\template\工作方案编审.docx'); $templateProcessor->setValue('clients','测试题目'); $templateProcessor->setValue('project','哈哈哈哈'); //保存文件 $templateProcessor->saveAs(ROOT_PATH.'public\template\jianding2.docx'); } |