N
N
NataliaCh2022-03-23 13:50:31
phpspreadsheet
NataliaCh, 2022-03-23 13:50:31

PhpWord: how to display a table correctly?

You need to put the table in the doc-file template. The table is taken from the database, where it is stored as html ($html_table).
the code:

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('tempatename.docx');
$wordTable = new \PhpOffice\PhpWord\Element\Table();
$wordTable->addRow();
$cell = $wordTable->addCell();  
 \PhpOffice\PhpWord\Shared\Html::addHtml($cell, $html_table);
$templateProcessor->setComplexBlock('html_table', $wordTable);
$templateProcessor->saveAs($pathToSave);

It all works.
But if the table has cell unions (the colspan and rowspan attributes), then the table is built without taking them into account, as if they do not exist. In the end, everything is crooked.
What can be done here?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question