How do I get HTML to format inside a table cell with addTable? I'll consider any method, even replacing HTML tags with wml
How do I get HTML to format inside a table cell with addTable? I'll consider any method, even replacing HTML tags with wml
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 replaceVariableByHTML or replaceVariableByWordFragment to replace it with a WordFragment of the HTML.
Regards.
Thanks, I understand how this would work, but since moving to the live server embedHTML no longer works, it actually gives an error 500 with nothing in the log. Any idea what could be causing this?
Hello,
Maybe Tidy for PHP (http://php.net/manual/en/book.tidy.php) is not installed or enabled?
A 500 error is a generic PHP error and it should always being added to the log, we recommend to check your server configuration to find where are those errors added.
We also recommend you test the included samples (addText and embedHTML) using PHP CLI mode to check if the problem is from some missing PHP extension (ZIP, XML, Tidy), missing rw access, a license error or any other source.
Regards.
Got it working by installing PHPtidy and validating the HTML, it seemed that & signs were causing some issues
$doc = new DOMDocument();
$data_text = str_replace(' ', ' ', $data_text);
$data_text = str_replace('&', '&', $data_text);
$doc->loadHTML($data_text);
$html = new WordFragment($docx, 'document');
$html->embedHTML($doc->saveHTML());