我正在使用phpdocx生成word文档。
我已经动态地改变了头部的文字。所以我想动态地替换头变量。phpdocx论坛他们说可以使用WordFragment方法来实现,但它不起作用..http://www.zxcv.phpdocx.com/en/forum/default/topic/734
下面是我将$TESTTT$变量放在标题中的代码
//path to the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocxFromTemplate('Doc.docx');
//create the Word fragment that is going to replace the variable
$wf = new WordFragment($docx, 'document');
$text='try to add head';
$wf->addText($text);
$docx->replaceVariableByWordFragment(array('TESTTT' => $wf), array('type' => 'block'));
$docx->createDocx('tessst');发布于 2014-10-01 16:00:26
从模板创建时,您还需要添加:
require_once '../../../classes/CreateDocxFromTemplate.inc';
发布于 2014-11-29 01:30:05
你真的需要使用单词片段吗?
使用PHPDocx,您可以轻松地替换文本变量和占位符图像,这在大多数情况下应该足够了。
如果不是这样,您可以使用导入页眉和页脚方法,或者将整个内容替换为add header方法。
发布于 2015-01-12 15:40:02
目前,phpdocx不支持通过单词片段改变变量,无论是页眉还是页脚。
https://stackoverflow.com/questions/26116778
复制相似问题