0
我想用replaceVariableByHTML函數替換word中的多重變量,並且我用replaceVariableByText替換文本。如果我只使用replaceVariableByText,一切都很好,但添加html替換會導致麻煩 - doc不會生成。我試圖用HTML代碼替換變量,但我只能替換一個變量。難道我做錯了什麼?這是我的代碼:多個replacevariablebyhtml不工作 - PHPDocX
//$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);