テンプレートを使用して、WordFragment または addExternalFile を使用せずにそのテンプレートで特定のページを複製することは可能ですか (テンプレートを 1 つのファイルのみにしたい)?
例として、私は 3 ページを持っています。ページ 2 を 4 回複製 (または繰り返し) したいので、結果として 7 ページの文書があり、2 ページ目が 4 回繰り返されますか? WordFragment または addExternalFile なしでそれを行うことは可能ですか? テンプレートで編集しやすくしたいからです。
私の Phpdocx は試用版です。
私がこれまでに試したことは、ドキュメント テンプレート (2 ページ目) で $wordfragment$ 変数を使用して wordfragment を使用し、php でこれを行うことです。
$wf = new WordFragment($docx, 'document');
for($i = 0: $<4; $i++) {
/*here I put a code to make a text and table in wordfragment (sorry it's too long to write it here, it's about 500 lines)*/
$wf->addBreak(array('type'=>'page')); //it's to go to next page
} //so this loop will make 4 same pages with the content I want in that 500 lines of code.
$docx->replaceVariableByWordFragment(array('wordfragment'=>$wf), array('type'=>'block'));
上記のように WordFragment を使用すると、実際には非常に強力で、非常に優れた結果が得られますが、ユーザーが使用するため、ユーザーはコードが苦手であると常に想定しているため、ユーザーに編集させることはできません。テンプレートを編集したいだけの場合のコード、たとえば、ユーザーがテンプレートのテーブルを編集したい場合、私のこのコードでは、そのユーザーはその500行のコードで編集する必要があり、それはユーザーではありませんフレンドリーで、私が望んでいたのは、それをよりシンプルにし、テキストと表を単語で作成し (ユーザーがそこで編集できるようにするため)、コードでそのページを繰り返すことだけです。出来ますか?
ああ、もう 1 つの方法である addExternalFile は実際には非常に優れていますが、これを使用すると、複数のテンプレートが必要になります。たとえば、start.docx、content.docx、end.docx という名前の 3 つのドキュメントが必要です。addExternalFile を使用すると、次のように使用できます。
$wf = new WordFragment($docx, 'document');
$wf->addExternalFile(array('src'=>'start.docx'));
$wf->addBreak(array('type'=>'page'));
for($i=0;$i<4;$i++) {
$content = new CreateDocxFromTemplate('content.docx');
/*here I put a code to replace all text and table variable in template*/
$content->replaceVariableByText($variables, $parameter); //$variables and $parameter already included in my code
$content->replaceTableVariable($table); //$table already included in my code
$content->createDocx('newcontent.docx');
$wf->addExternalFile(array('src'=>'newcontent.docx'));
$wf->addBreak(array('type'=>'page'));
} //this loop will make 4 same page
$wf->addExternalFile(array('src'=>'end.docx');
$docx->replaceVariableByWordFragment(array('wordfragment'=>$wf), array('type'=>'block'));
addExternalFile を使用すると、wordfragment ではなくドキュメントにテキスト、変数を書き、表を描画することができました。非常にユーザーフレンドリーですが、ユーザーが編集したい場合、この方法では少なくとも3つの異なるドキュメントを開く必要があるという欠点があります。私が欲しいのは 1 つのドキュメントだけです。すべてのテキスト、変数、およびテーブルがドキュメントにあり、php コードにテキストやテーブルはありません。phpDocxでこれを行う方法はありますか?