我正在尝试使用 replaceVariableByHTML 函数替换 word 中的多桩变量,并且我正在使用 replaceVariableByText 替换文本。如果我只使用 replaceVariableByText 一切正常,但添加 html 替换会导致麻烦 - 文档不会生成。我试图只用 HTML 代码替换变量,但我只能替换一个变量。难道我做错了什么?这是我的代码:
//$htmlData and $data are array('name' => 'value')
$docx = new \CreateDocxFromTemplate($templateDir);
$docx->setTemplateSymbol('‡');
$docx->replaceVariableByText($data, array());
foreach($htmlData as $key => $value)
$docx->replaceVariableByHTML($key, 'block', $value);
$filename = uniqid();
$uniqName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename.'';
$docx->createDocx($uniqName);
header('Content-Type: application/vnd.openxmlformats-officedocument.' .
'wordprocessingml.document');
header('Content-Disposition: attachment; filename="' . $templateSymbol .
'.' . $this->documentExtension . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($uniqName . '.' . $this->documentExtension));
readfile($uniqName . '.' . $this->documentExtension);