4.phpword 实现word文件模板字符替换

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');
    }

}
文字替换实现代码
内容模版
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,362评论 0 3
  • 工欲善其事,必先利其器。总结一下,方便多了。R语言还是很牛逼的,可以干很多事情。有一把顺手的刀还是很重要的。 0....
    Liam_ml阅读 4,880评论 1 60
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    小迈克阅读 3,134评论 1 3
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,915评论 2 45
  • 291976-陈国艳《2017-10-16》 [连续第247天总结] A目标完成情况。 ppt制作,20分钟,完成...
    科研女神经阅读 127评论 0 0

友情链接更多精彩内容