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

How to set fixed width for tables in phpword (auto fit : fixed column width) #531

Open
hari-web opened this issue May 4, 2015 · 2 comments

Comments

@hari-web
Copy link

hari-web commented May 4, 2015

Hi,

Im using phpword version 0.12.0. I have a problem on managing large contents writing inside cell. Even the cell have some fixed width , if the content too large (case when there is no space between characters), cell layouts becomes broken. (please see the image)
![enter image description here][1]
Any one know how to solve this situation. Thanks in advance
word


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@robBinlzX
Copy link

I just found out that you have to set style "layout" fixed on your table like below

$fancyTableStyle = [
    'borderSize'  => 6,
    'borderColor' => '000000',
    'cellMargin'  => 80,
    'alignment'   => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
    'layout'      => \PhpOffice\PhpWord\Style\Table::LAYOUT_FIXED,
];
$table = $section->addTable($fancyTableStyle);

and then the long word will wrap itself inside the cell.

If you preset a table style on your phpword object, the layout style won't work.

$fancyTableStyleName = 'Fancy Table';
$fancyTableStyle = [
    'borderSize'  => 6,
    'borderColor' => '000000',
    'cellMargin'  => 80,
    'alignment'   => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER,
    'layout'      => \PhpOffice\PhpWord\Style\Table::LAYOUT_FIXED,
];
//table will not be fixed
$table = $section->addTable($fancyTableStyleName);

In ms word you also need to set the autofit option directly on each table, maybe that's why.

I think this issue can be closed?

@github-actions
Copy link

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 Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants