0

replaceVariableByHTML 関数を使用して単語内の複数の変数を置き換えようとしています。また、 replaceVariableByText を使用してテキストを置き換えています。replaceVariableByText のみを使用している場合はすべて問題ありませんが、html 置換を追加すると問題が発生します - ドキュメントが生成されません。変数を HTML コードのみに置き換えようとしましたが、1 つの変数しか置き換えられません。私は何か間違ったことをしていますか?これは私のコードです:

//$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);
4

1 に答える 1

0

あなたの声明は完全ではないかもしれないと思います。

ドキュメントによると、次のように形成する必要があります。

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

于 2015-02-05T13:42:58.237 に答える