4

In my PHPWord document I have a section with landscape orientation and table in it. I want the table to be full-width, but if I add table like this (since width is in percent according to the docs):

$table = $section->addTable(array('width' => 100));

or like this:

$table = $section->addTable(array('unit' => 'pct', 'width' => 5000));

my table is not full-width (actually, it seems that the table takes up the entire width, but for portrait orientation).

I can achieve the desired result in this way:

// Generate document
$word = new PHPWord();
$section = $word->addSection(array());
$sectionStyle = $section->getStyle();
$sectionStyle->setOrientation($sectionStyle::ORIENTATION_LANDSCAPE);

// Add table
$table = $section->addTable(array());
$tableStyle = $table->getStyle();
$tableStyle->setUnit($tableStyle::WIDTH_TWIP);
$tableStyle->setWidth($sectionStyle->getPageSizeW() - $sectionStyle->getMarginLeft() - $sectionStyle->getMarginRight());

But I doubt that this is good solution. Is there a better solution?

Sergey Novikov
  • 4,096
  • 7
  • 33
  • 59
  • 1
    Did you ever find an elegant solution around this? All I need is something like fullWidth => true, and then being able to set the cells width as a percentage. It's particularly difficult when providing dynamic page sizes, eg A4, A4, Letter, Legal. – Maurice Aug 15 '18 at 02:08

0 Answers0