您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

TP框架如何实现php数据导出word详解

2024/3/28 21:19:12发布8次查看
本文主要和大家分享tp框架如何实现php数据导出word详解,希望能帮助到大家。
1、使用composer安装phpexcel (composer安装方法→点我)composer require phpoffice/phpexcel
2、引入相关类
use phpword_iofactory; use phpword;
3、具体实现方法//调用插件 vendor('phpword'); vendor('phpword.iofactory'); $phpword = new \phpoffice\phpword\phpword(); //实例化phpword类 $properties = $phpword->getdocinfo(); $properties->setcreator('my name'); //创建者 $properties->setcompany('my factory'); //公司 $properties->settitle('my title'); //biao $properties->setdescription('my description'); //描述 $properties->setcategory('my category'); //分类 $properties->setlastmodifiedby('my name'); //最后修改者 $properties->setcreated( mktime(0, 0, 0, 3, 12, 2010) ); //创建时间 $properties->setmodified( mktime(0, 0, 0, 3, 14, 2010) ); //修改时间 $properties->setsubject('my subject'); //主题 $properties->setkeywords('my, key, word'); //关键字 $sectionstyle = array( 'orientation' => null, //页面方向默认竖向 'marginleft' => 900, 'marginright' => 900, 'margintop' => 900, 'marginbottom' => 900); $section = $phpword->addsection($sectionstyle); //创建一个有样式的页面
可用部分样式选项:
borderbottomcolor。边框底部的颜色。
borderbottomsize。边框底部尺寸(以缇为单位)。
borderleftcolor。边框留下颜色。
borderleftsize。边框左侧大小(以缇为单位)。
borderrightcolor。边框正确的颜色。
borderrightsize。边框正确尺寸(以缇为单位)。
bordertopcolor。边框顶部的颜色。
bordertopsize。边框顶部尺寸(以缇为单位)。
breaktype。分节符类型(nextpage,nextcolumn,continuous,evenpage,oddpage)。
colsnum。列数。
colsspace。列之间的间距。
footerheight。页脚底部的间距。
gutter。页面排水沟间距。
headerheight。间距到标题顶部。
margintop。页面页边距(以缇为单位)。
marginleft。页面空白(以缇为单位)。
marginright。正确的页边距(以缇为单位)。
marginbottom。页边距底部(以缇为单位)。
orientation。页面方向(portrait,这是默认的,或landscape)。
pagesizeh。页面高度(以缇为单位)。由orientation选项隐式定义。不鼓励任何改变。
pagesizew。页面宽度(以缇为单位)。由orientation选项隐式定义。不鼓励任何改变。
//设置文本样式 $fontstyle = [ 'bgcolor' => 'red', //字体背景色 'bold' => true, //是否加粗 'size' => '20', 'color' => 'green', //字体颜色 'doublestrikethrough' => true //双实线 ]; //设置段样式 $paragraphstyle = [ 'bidi' => true, //从左到左 ]; $text = '所添加的文本内容'; //添加文本 $section->addtext($text, $fontstyle, $paragraphstyle);
可用字体样式选项:
allcaps。全部大写,对或错。
bgcolor。字体背景颜色,例如ff0000。
bold。大胆,真实或虚假。
color。字体颜色,例如ff0000。
doublestrikethrough。双删除线,真或假。
fgcolor。字体突出显示颜色,例如黄色,绿色,蓝色。
请参阅\phpoffice\phpword\style\font::fgcolor_...常量以获取更多值
hint。字体内容类型,默认,eastasia或cs。
italic。斜体,真或假。
name。字体名称,例如arial。
rtl。从右到左的语言,真或假。
size。字体大小,例如20,22。
smallcaps。小型大写,真或假。
strikethrough。删除线,真或假。
subscript。下标,真或假。
superscript。上标,对或错。
underline。下划线,单个,短划线,点缀等
请参阅\phpoffice\phpword\style\font::underline_...常量以获取更多值
lang。语言,如en-us,fr-be等语言代码或者如果需要设置eastasian或双向语言的对象(或数组)
查看\phpoffice\phpword\style\language一些语言代码的类。
可用的段落样式选项:
alignment。支持自ecma-376标准第1版以来的所有对齐模式,直到iso / iec 29500:2012。
查看\phpoffice\phpword\simpletype\jc课程的细节。
basedon。父母的风格。
hanging。挂多少钱。
indent。缩小多少。
keeplines。将所有行保留在一页上,为true或false。
keepnext。用下一段保留段落,对或错。
lineheight。文本行的高度,例如1.0,1.5等等
next。下一款的风格。
pagebreakbefore。在下一页开始段落,是true还是false。
spacebefore。段落之前的空格。
spaceafter。段落后的空格。
spacing。线条之间的空间。
spacinglinerule。行间距规则。自动,确切,atleast
tabs。一套自定义选项卡停止。
widowcontrol。允许第一行/最后一行显示在单独的页面上,true或false。
contextualspacing。在使用相同样式时,忽略上下方向的间距,true或false。
bidi。从右到左的段落布局,true或false。
shading。段落阴影。
textalignment。线上的垂直字符对齐。
查看\phpoffice\phpword\simpletype\textalignment课程可能的值。
//添加标题(相关样式需要单独设置) $phpword->addtitlestyle(1, $fontstyle, $paragraphstyle); $section->addtitle('所添加的标题内容', 1);
添加标题:
$phpword->addtitlestyle($depth, [$fontstyle], [$paragraphstyle]);
$section->addtitle($text, [$depth]);
$linksrc = 'https://www.baidu.com'; //链接地址 $linkname = '百度搜索'; //链接名称 //添加超链接(相关样式需要单独设置) $section->addlink($linksrc, $linkname, $fontstyle, $paragraphstyle);
添加超链接:
$section->addlink($linksrc, [$linkname], [$fontstyle], [$paragraphstyle]);
//添加页脚方法 $footer = $section->addfooter(); $footer->addpreservetext('page {page} of {numpages}.'); //向页眉或页脚添加页码或页数 $breakcount = 10; //设置换行数 $section->addtextbreak($breakcount, $fontstyle, $paragraphstyle); //设置换行 $section->addpagebreak(); //添加换页符 $section->addlistitem("list1", 1, $fontstyle, $paragraphstyle); //创建列表 $section->addlistitem("list2", 1, $fontstyle, $paragraphstyle); $section->addlistitem("list3", 1, $fontstyle, $paragraphstyle); $objwriter = \phpoffice\phpword\iofactory::createwriter($phpword, 'word2007'); $objwriter->save('aa.docx'); //生成word文件
相关推荐:
迅速掌握php导出word文档原理_php教程
php导出word形式
php导出word格式数据的范例代码
以上就是tp框架如何实现php数据导出word详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product