Forum


Replies: 8   Views: 323
Word to html, display empty line breaks, and work with tables using addtable
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 23-10-2024 - 15:04

Hello,

You can use template methods at the same time with the same template as many times as you need.

Please note that replaceVariableByText replaces a text placeholder with new text content. To use replaceTableVariable the placeholders must be added to a table.

If you want to replace a text placeholder with a table (or any other complex content such as images, charts, text with next styles...), you need to use replaceVariableByWordFragment. For example:

$tableWordFragment = new WordFragment($docx);
$valuesTable = array(
    array(11, 12, 13, 14),
    array(21, 22, 23, 24),
    array(31, 32, 33, 34),
);
$paramsTable = array('border' => 'single', 'tableAlign' => 'center');
$tableWordFragment->addTable($valuesTable, $paramsTable);

$docx->replaceVariableByWordFragment(array('VAR' => $tableWordFragment));

Please note that replaceVariableByWordFragment does "block" type replacements by default.

For more information about WordFragments, we recommend you read the documentation at https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml and check the samples included in the package (Templates/replaceVariableByWordFragment folder).

Regards.