项目地址:
https://gitee.com/colin_86/MDword
https://github.com/mkdreams/MDword
-
安装
//方法一
composer require mkdreams/mdword
//方法二,手动引入自动加载类
require_once('Autoloader.php');
-
给母版“temple.docx”添加批注
-
调用方法(可参考此实例:tests\samples\simple for readme)
//新建类 加载 母版
$TemplateProcessor = new WordProcessor();
$template = 'temple.docx';
$TemplateProcessor->load($template);
//赋值
$TemplateProcessor->setValue('value', 'r-value');
//克隆并复制
$TemplateProcessor->clones('people', 3);
$TemplateProcessor->setValue('name#0', 'colin0');
$TemplateProcessor->setValue('name#1', [['text'=>'colin1','style'=>'style','type'=>MDWORD_TEXT]]);
$TemplateProcessor->setValue('name#2', 'colin2');
$TemplateProcessor->setValue('sex#1', 'woman');
$TemplateProcessor->setValue('age#0', '280');
$TemplateProcessor->setValue('age#1', '281');
$TemplateProcessor->setValue('age#2', '282');
//图片复制
$TemplateProcessor->setImageValue('image', dirname(__FILE__).'/logo.jpg');
//删除某行
$TemplateProcessor->deleteP('style');
//保存
$rtemplate = __DIR__.'/r-temple.docx';
$TemplateProcessor->saveAs($rtemplate);
-
结果
-
动图