首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个replacevariablebyhtml不工作- PHPDocX

多个replacevariablebyhtml不工作- PHPDocX
EN

Stack Overflow用户
提问于 2015-02-05 13:34:06
回答 1查看 662关注 0票数 0

我试图用replaceVariableByHTML函数替换word中的多个变量,并使用replaceVariableByText替换文本。如果我只使用replaceVariableByText,一切都好,但是添加html替换会带来麻烦--文档没有生成。我试图用HTML代码替换变量,但只能替换一个变量。我做错什么了吗?这是我的密码:

代码语言:javascript
复制
//$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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-05 13:42:58

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

根据这些文件,应将其组成如下:

代码语言:javascript
复制
public replaceTemplateVariableByHTML (string $var, string $type, string $html [, array $options]) 

根据您想要实现的具体目标,您可以尝试如下:

代码语言:javascript
复制
$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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28345313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档