Forum


Replies: 5   Views: 384
Html in table cell
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  · 07-11-2018 - 14:38

Hello,

The addTable method, as other methods, allows adding WordFragments (https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml) as contents.

You just need to create a new WordFragment, insert the HTML and then add the values to the table:

$html = new WordFragment($docx);
$html->embedHTML($htmlContent);

$valuesTable = array(
  array(
    'Title A',
    'Title B',
    'Title C',
  ),
  array(
   'Line A',
   'Line B',
   $html,
  ),
);

$docx->addTable($valuesTable);

You can see a full sample using WordFragments on the API page of the method (https://www.phpdocx.com/api-documentation/word-content/add-table-Word-document-with-PHP).

You can also add a placeholder to the table as value an then use replaceVariableByWordFragment to replace it with a WordFragment of the HTML.

Regards.