Ai
1 Star 7 Fork 4

牛牛/word

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.php 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
牛牛 提交于 2020-08-05 16:19 +08:00 . first commit
<?php
include_once "vendor/autoload.php";
$tmp = new \PhpOffice\PhpWord\TemplateProcessor('tmp.docx');//打开模板
//1变量替换
$tmp->setValue('name', '李四');//替换变量name
$tmp->setValue('mobile', '18888888888');//替换变量mobile
//2复制行
$arr = [
['school' => '大学', 'year' => '2014'],
['school' => '大学', 'year' => '2014'],
['school' => '大学', 'year' => '2014'],
['school' => '大学', 'year' => '2014'],
['school' => '大学', 'year' => '2014'],
['school' => '大学', 'year' => '2014'],
['school' => '大学', 'year' => '2014'],
];
$rows = count($arr);//总行数
$tmp->cloneRow('school', $rows);//复制行
for ($i = 0; $i < $rows; $i++) {
$tmp->setValue("school#" . ($i + 1), $arr[$i]['school']);//替换变量
$tmp->setValue("year#" . ($i + 1), $arr[$i]['year']);
}
//3块操作
$winning_record = "";
if ($winning_record != '') {
$tmp->cloneBlock('WIN_BLOCK', 1);
$tmp->setValue('winning_record', $winning_record);
} else {
#$tmp->deleteBlock('WIN_BLOCK');//这个方法会出错,原因不知,用cloneBlock来代替
$tmp->cloneBlock('WIN_BLOCK', 0);
}
//图片
$tmp->setImageValue('header', ['path' => '1.jpg']);
// 设置图片宽高
$tmp->setImageValue('header', ['path' => '1.jpg','width'=>500,'height'=>500]);
// 设置多次替换
$tmp->setImageValue('header', ['path' => '1.jpg','width'=>500,'height'=>500],3);
$tmp->saveAs(time() . '_简历.docx');//另存为
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/nyg1991/word.git
git@gitee.com:nyg1991/word.git
nyg1991
word
word
master

搜索帮助