1 Star 0 Fork 35

曲子陌 / MDword

forked from colin_86 / MDword 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

MDword

项目通用名称

母版:在某个word基础上修改的,这个word命名为“母版”
区块:也就是要被替换或者克隆的部分呢

项目介绍

主要用途:动态生成word
优势:生成word只需关注动态数据及逻辑,无需关注式样的调整(式样可以借助office word调整母版即可)

与PHPWord的爱恨情仇

  • 共同点

  1. PHP编写的库(资源包)
  2. 用于生成office word
  • 不同点

  1. PHPWord 需要一个元素一个元素的写入,而MDword则是在母版的基础上修改,编码效率更高
  2. 修改文字式样,增加封面,修改页眉页脚MDword只需用word编辑软件调整母版,而PHPWord需要繁琐的去调整每个元素

教程

  • 安装

//方法一
composer require mkdreams/mdword
//方法二,手动引入自动加载类
require_once('Autoloader.php');
  • 给母版“temple.docx”添加批注

image

//新建类 加载 母版
$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],
    ['text'=>1,'type'=>MDWORD_BREAK],
    ['text'=>'86','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);
  • 结果

image

  • 动图

image

更多案例

交流

请备注:MDword交流

image

项目计划

Copyright mkdreams Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

MDword 是一个 PHP 动态生成 word 的项目 展开 收起
PHP
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/qzm123/MDword.git
git@gitee.com:qzm123/MDword.git
qzm123
MDword
MDword
main

搜索帮助