PHPWord
PHPWord copied to clipboard
Generate word from html table, width problem
Hi, I need to create a word file from PHP. I create a HTML string into PHP and use PhpWord to create a file
`$phpWord = new \PhpOffice\PhpWord\PhpWord();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html); `
This is my simple table:
unfortunately I can't share the table code in this post
`
Nome e Cognome | |
Luogo e data di nascita |
Hi!
I think that problem is in src/PhpWord/Element/Cell.php::__construct.
When I use \PhpOffice\PhpWord\Shared\Html::addHtml for parsing html fragment:
<table>
<tr>
<td style="width:10%;">10%</td>
<td style="width:90%;">90%</td>
</tr>
</table>
width not working, because method src/PhpWord/Shared/Html::parseCell make Cell instanse without width from style attribute.
[UPDATE 1] /21.06.2022 Yes. There is problem in src/PhpWord/Style/Cell::setWidth. The method does not assign anything. And for now I don't know how to fix it.
[UPDATE 2] /21.06.2022 This is my hotfix for my task. If you know how many columns you have you can set width directly for first row (see screenshots down). Mybe this is solution is not correct/not nice, but for me this is works...
try table-layout:auto
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.