Forum


Replies: 8   Views: 215
Word to html, display empty line breaks, and work with tables using addtable

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.