Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate word from html table, width problem #2235

Open
lsantaniello opened this issue May 28, 2022 · 4 comments
Open

Generate word from html table, width problem #2235

lsantaniello opened this issue May 28, 2022 · 4 comments

Comments

@lsantaniello
Copy link

lsantaniello commented May 28, 2022

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
@vireks
Copy link

vireks commented Jun 21, 2022

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

@raybon-lee
Copy link

try table-layout:auto

@github-actions
Copy link

github-actions bot commented Oct 3, 2022

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 github-actions bot added the Stale label Oct 3, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
@Ilyakucher23
Copy link

Have the same issue

@Progi1984 Progi1984 added this to the 2.0.0 milestone Aug 9, 2024
@Progi1984 Progi1984 modified the milestones: 1.3.0, 1.3.1 Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants