PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.25k stars 2.69k forks source link

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

Open hari-web opened 9 years ago

hari-web commented 9 years ago

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!](https://www.bountysource.com/issues/13035824-how-to-set-fixed-width-for-tables-in-phpword-auto-fit-fixed-column-width?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github).
robBinlzX commented 5 years ago

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[bot] commented 1 year ago

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.