27 Star 261 Fork 35

colin_86 / MDword

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

MDword

English document

项目通用名称

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

项目介绍

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

与PHPWord的爱恨情仇

  • 共同点

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

  1. PHPWord 专注于一个元素一个元素的写入,而MDword则是专注于在母版的基础上修改,功能更强大,编码效率更高
  2. 修改文字式样,增加封面,修改页眉页脚MDword只需用word编辑软件调整母版,而PHPWord需要繁琐的去调整每个元素
  3. 可以自动生成目录

教程

  • 安装

//方法一
composer require mkdreams/mdword
//方法二,手动引入自动加载类
require_once('Autoloader.php');
  • 给母版“temple.docx”添加批注,或者添加“${value/}”这类特殊文字,注意结尾有个“/”。

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

性能情况(统计脚本

测试项 用时(S)
1页母版赋值100次 0.04
1页母版赋值500次 0.16
1页母版赋值1000次 0.33
1页母版赋值10000次 7.80
1750页母版赋值100次 4.61
1750页母版赋值500次 4.94
1750页母版赋值1000次 5.43
1750页母版赋值10000次 17.39

内存使用情况(统计脚本

连续运行第几次 累积内存使用情况 备注
1 0.050590515136719 M 首次需要加载PHP类
2 0.050949096679688 M
3 0.050949096679688 M
4 0.050949096679688 M
5 0.050949096679688 M
6 0.050949096679688 M
7 0.050949096679688 M
8 0.050949096679688 M

更多案例

交流

请备注: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 的项目; word 模板引擎 展开 收起
PHP 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助