PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Generate word from html table, width problem

Open lsantaniello opened this issue 2 years ago • 4 comments

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

`

`

Unfortunatly the column width is not recognized. the column width is adapted to the content.

How can I solve the problem? Could you please help me?

Thanks L

Nome e Cognome
Luogo e data di nascita

lsantaniello avatar May 28 '22 11:05 lsantaniello

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.

image

image

[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.

image image

[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...

image image

vireks avatar Jun 21 '22 17:06 vireks

try table-layout:auto

raybon-lee avatar Jul 04 '22 15:07 raybon-lee

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.

github-actions[bot] avatar Oct 03 '22 02:10 github-actions[bot]