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插件文件及中文技术文档下载
推荐的文章
随手记
PHP经验分享
- ● MySQLSUM在没有符合查询条件时返回结果为空的处理办法
- ● 如何开启PHP8的JIT提升运行速度
- ● 钉钉API接口-用PHP+Curl实现获取用户信息
- ● 钉钉API接口-用PHP+Curl实现获取应用Access_Token
- ● 在PHP中使用CURL,“撩”服务器只需几行——phpcurl详细解析和常见大坑
- ● MySQLInnodb并发涉及参数说明
- ● mysql参数调优之innodb_thread_concurrency、innodb_concurrency_tickets合理的使用cpu性能
- ● PHP用fsockopen检测指定IP端口是否开启可用
- ● PHP用socket检测服务器IP端口是否开放?代码示例
- ● GatewayWorker报错:Waring:Events::onMessageisnotcallable