欢迎您来到,李雷博客 | PHP博客        登录  |  注册

PHPWord插件创建表格及模板替换技术记录说明(含PHPWord文件及中文技术文档下载)

更新:2018-07-18 17:17:31
人气:7975
来源:本站原创
A+

1.模板替换功能

require_once 'PHPWord.php';
require_once 'PHPWord/IOFactory.php';

$PHPWord = new PHPWord();

$template = $PHPWord->loadTemplate('PHPWord/mb/test.docx');
$template->setValue('Name','你好,测试-123abc');//${Name}
$template->setValue('Street', 'Coming-Undone-Street 32');
	
$filename = 'PHPWord/mb/test_update.docx';
$template->save($filename);

2.直接创建表格

$section = $PHPWord->createSection();

$styleTable = array('borderSize'=>6, 'borderColor'=>'000000', 'cellMargin'=>80);//表格样式
$fontStyle = array('bold'=>true, 'align'=>'center');//文字样式

$PHPWord->addTableStyle('table_1', $styleTable);//定义表格样式
$table = $section->addTable('table_1');

$table->addRow(400);
$table->addCell(2000)->addText('Cell 1',$fontStyle);
$table->addCell(2000)->addText('Cell 2',$fontStyle);
$table->addCell(2000)->addText('Cell 3',$fontStyle);

$table->addRow(1000);
$table->addCell(2000)->addText('Cell 4',$fontStyle);
$table->addCell(2000)->addText('Cell 5',$fontStyle);
$table->addCell(2000)->addText('Cell 6',$fontStyle);

$objWrite = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$filename = 'PHPWord/mb/test_create.docx';
$objWrite->save($filename);

3.PHPWord插件文件及中文技术文档下载

PHPWORD中文技术文档.docx

PHPWord.zip


推荐的文章
# 发表我的评论
  /     /  
# 最近评论
暂时还没有评论,要不要说点什么?
  Ads by Google
  联系博主
Hello,本博客系统采用PHP和MySql开发,程序开发完全是因为个人爱好,是自己纯手写PHP源代码,未采用任何PHP框架!
QQ:858353007   微信号:lileihot123
网站地图
会员服务
关于我们
QQ:858353007
 
广告服务
加我微信
移动端访问
 
 
Copyright © 2014- 2024 www.mdaima.com All Rights Reserved.
李雷博客,专注PHP经验、PHP教程及PHP源代码开源下载分享的PHP博客!   ICP备案号:京ICP备10202169号-4