我试图用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);发布于 2015-02-05 13:42:58
我相信你的陈述可能不完整。
根据这些文件,应将其组成如下:
public replaceTemplateVariableByHTML (string $var, string $type, string $html [, array $options]) 根据您想要实现的具体目标,您可以尝试如下:
$docx->replaceVariableByHTML($key, 'block', $value, array('isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => true)););您可以相应地更改isFile、parseDivsAsPs和downloadImages属性,但是应该传递isFile属性。
以下是完整的信息:http://www.phpdocx.com/api-documentation/templates/replace-variable-html-Word-document
https://stackoverflow.com/questions/28345313
复制相似问题