3

I want to insert dynamic sections and table rows with images to a word template. As an example assume template contains 1-5 sections and I want to insert 6 - n sections/sub sections dynamically.

I checked the requirement with PHP Word and TinyButStrong. But both support only for replacing keywords.

I was able to achieve this using PHP Word by creating the document from the scratch but I want to do the same with template, because most of the part in the document are static, only few sections to be added dynamically and number of sections to be added are unknown.

Do you know any PHP library that meet the requirement? Is there any workaround for this?

Aruna
  • 91
  • 1
  • 9
  • You could check my old answer about reusing template sections in phpword: http://stackoverflow.com/questions/33250803/reuse-template-in-the-same-document-phpword/33257181#33257181. In that example you can see how to define dynamically the number of cloned template blocks and how to access them. – ejuhjav May 18 '16 at 06:09

1 Answers1

0

You can create document from template and then put there new dynamic date replacing some variables with setComplexBlock functions:

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_40_TemplateSetComplexValue.docx');

$inline = new TextRun();
$inline->addText('by a red italic text', array('italic' => true, 'color' => 'red'));
$templateProcessor->setComplexValue('inline', $inline);

See full example here: https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_40_TemplateSetComplexValue.php.

igronus
  • 486
  • 4
  • 12