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

Table: fix row width #560

Open
HaydenHewlett opened this issue Jun 22, 2015 · 1 comment
Open

Table: fix row width #560

HaydenHewlett opened this issue Jun 22, 2015 · 1 comment

Comments

@HaydenHewlett
Copy link

HaydenHewlett commented Jun 22, 2015

Hello!

I have a problem with table rows: I want to fix the width and when a user adds text in the generated document the width stills fixed.
Actually it seems the $table->addCell($width); gives only a min-width for the cell and i want to set a max.

Can I do that?


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?

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

2 participants