According to documentation this should write a 100% width table but width is ignored:
$table_style = array(
'unit' => \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT,
'width' => 100 * 50,
);
$php_word->addTableStyle('myTable', $table_style);
$table = $section->addTable('myTable');
Only the following writes a 100% width table as expected:
$table = $section->addTable(array(
'unit' => \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT,
'width' => 100 * 50,
));
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
I can confirm this with the last version of PHPWord.
Also confirmed.
Yes, this is the case. I'm not sure why you also need 100 * 50 for the width. It's possible that if the width is just set to a really large number then it just takes up 100%.
Edit: I just saw the comment:
// Width in fiftieths (1/50) of a percent (1% = 50 unit)
Seems to be a word thing.
The table style class works well for setting items like so:
// Create a new table style
$table_style = new \PhpOffice\PhpWord\Style\Table;
$table_style->setBorderColor('cccccc');
$table_style->setBorderSize(1);
$table_style->setUnit(\PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT);
$table_style->setWidth(100 * 50);
// Add a section to the document.
$section = $this->phpword->addSection();
// Set up our table.
$table = $section->addTable($table_style);
There's a setStyleName on a parent class which just sets $this->styleName, and I'm not sure if there's a way to subsequently refer to the style by name.
Just hit this bug as well.
Does anyone know the status of this bug? I just installed phpoffice/phpword a couple days ago, and while developing my code, I noticed this same thing is happening. Very Confusing. Thanks @ant-s for the alternative.
me too……on "phpoffice/phpword": "^0.16.0" (composer.json)
Same issue, trying to use a style defined in my document template example "TBL1" but also specify the table width which must be set per table. Seems it is not part of the style in MsWord.
Most helpful comment
The table style class works well for setting items like so:
There's a setStyleName on a parent class which just sets $this->styleName, and I'm not sure if there's a way to subsequently refer to the style by name.