Javascript 多个replacevariablebyhtml不起作用-PHPDocX

Javascript 多个replacevariablebyhtml不起作用-PHPDocX,javascript,php,ms-word,phpdocx,Javascript,Php,Ms Word,Phpdocx,我正在尝试使用replaceVariableByHTML函数替换word中的多文件变量,并且我正在使用replaceVariableByText替换文本。如果我只使用replaceVariableByText,一切正常,但添加html替换会导致问题-文档无法生成。我试图用HTML代码替换变量,但我只能替换一个变量。我做错什么了吗?这是我的代码: //$htmlData and $data are array('name' => 'value') $docx = new \CreateDoc

我正在尝试使用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);

我相信你的陈述可能不完整

根据文件规定,其格式应为:

public replaceTemplateVariableByHTML (string $var, string $type, string $html [, array $options]) 
根据您的具体目标,您可以尝试以下方法:

$docx->replaceVariableByHTML($key, 'block', $value, array('isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => true)););
您可以相应地更改isFile、parsedivsasp和downloadImages属性,但是应该传递isFile属性

以下是完整信息: