我正在使用 phpdocx 来生成 word 文档。
我已经动态地改变了文字的标题。所以我想用 dnamically 替换标题变量。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');