IDC知识库
IDC领域专业知识百科平台

网站制作简历php

网站制作简历php操作word有一个非常好用的模板,就是phpword,该轮子可以在github上查找到(PHPOffice/PHPWord)。上面有较为详细的例子和代码,其中里面的源码包含有一些常用的操作例子,包括设置页眉、页脚、页码、字体样式、表格、插入图片等常用的操作。这里介绍的是如何使用该轮子来制作一个简历。

在许多招聘网站都有一个简历下载的功能,如何用php实现呢?在PHPOffice/PHPWord里面就有一个非常简单的生成一个word文档,向文档中插入一些文字。这里我使用的方式比较取巧,这个轮子的说明文档中有template processing,我理解为模板替换,也就是跟laravel的blade模板一个概念。接下来就不多废话,直接说如何操作,这里提一句使用的是laravel框架。

1.安装PHPOffice/PHPWordcomposer require phpoffice/phpword

2.创建控制器DocController及test方法用于测试,并建立路由。php artisan make:controller DocController

3.建立word模板,这里说明一下,该轮子替换的是word文档中格式为${value}格式的字符串,这里我简易的搭建一个模板如下图1所示:

从图中可以看到有一些基本的信息,这些可以从数据库中捞取数据。不过这次是直接使用替换的方式,像工作经历和教育经历这种多行表格的模式这里也只需要取一行作为模板即可。

4.具体代码//load template docx

$templateProcessor = new TemplateProcessor(‘./sample.docx’);

//基础信息填写替换

$templateProcessor->setValue(‘update_at’, date(‘Y-m-d H:i:s’));

$templateProcessor->setValue(‘number’, ‘123456’);

$templateProcessor->setValue(‘Name’, ‘张三’);

$templateProcessor->setValue(‘sex’, ‘男’);

$templateProcessor->setValue(‘birth’, ‘1996年10月’);

$templateProcessor->setValue(‘age’, ’22’);

$templateProcessor->setValue(‘shortcut’, ‘待业/aaa’);

$templateProcessor->setValue(‘liveArea’, ‘福建省莆田市涵江区’);

$templateProcessor->setValue(‘domicile’, ‘福建省莆田市涵江区’);

$templateProcessor->setValue(‘address’, ”);

$templateProcessor->setValue(‘hopetodo’, ‘IT’);

$templateProcessor->setValue(‘hopeworkin’, ‘互联网’);

$templateProcessor->setValue(‘hopes’, ‘7000+’);

$templateProcessor->setValue(‘worklocation’, ‘福建省莆田市’);

$templateProcessor->setValue(‘phone’, ‘123456789’);

$templateProcessor->setValue(‘mail’, ‘456789@qq.com’);

$templateProcessor->setValue(‘qqnum’, ‘456789’);

$templateProcessor->setValue(‘selfjudge’, ‘哇哈哈哈哈哈哈哈’);

//工作经历表格替换

$templateProcessor->cloneRow(‘experience_time’, 2);//该表通过克隆行的方式,形成两行

$templateProcessor->setValue(‘experience_time#1’, ‘2010-09~2014-06’);//每行参数是用value#X(X表示行号,从1开始)

$templateProcessor->setValue(‘job#1’, ‘ABC company CTO’);

$templateProcessor->setValue(‘experience_time#2’, ‘2014-09~至今’);

$templateProcessor->setValue(‘job#2’, ‘JBC company CTO’);

//教育经历

$templateProcessor->cloneRow(‘time’, 2);

$templateProcessor->setValue(‘time#1’, ‘2010-09~2014-06’);

$templateProcessor->setValue(‘school#1’, ‘ABC’);

$templateProcessor->setValue(‘major#1’, ‘Computer science’);

$templateProcessor->setValue(‘time#2’, ‘2014-09~至今’);

$templateProcessor->setValue(‘school#2’, ‘JBC’);

$templateProcessor->setValue(‘major#2’, ‘Computer science’);

//语言能力

$templateProcessor->cloneRow(‘lang’,2);

$templateProcessor->setValue(‘lang#1’, ‘汉语|精通’);

$templateProcessor->setValue(‘lang#2’, ‘英语|精通’);

//技能

$templateProcessor->cloneRow(‘skill’,3);

$templateProcessor->setValue(‘skill#1’, ‘JAVA|精通’);

$templateProcessor->setValue(‘skill#2’, ‘Python|精通’);

$templateProcessor->setValue(‘skill#3’, ‘PHP|精通’);

// Saving the document

$templateProcessor->saveAs(‘my.docx’);

这样就可以通过建立word模板的方式产生一个简历了。

缃戠珯鍒朵綔
网站制作、网站优化、网站推广需要选择专业的域名服务商-域名频道
Linux虚拟主机适用于企业展示型网站、电子商务网站、论坛,支持Linux操作系统,配有MySQL数据库,LAMP环境。对于PHP程序支持较好。
免备案虚拟主机、低价格虚拟主机、海外虚拟主机免费虚拟主机、1G空间容量全能主机性价比高。
想使用价格合理且有保障的自助建站服务就到域名频道平台,申请链接点击http://www.dns110.com/web/

赞(0)
分享到: 更多 (0)

中国专业的网站域名及网站空间提供商

买域名买空间