PHPWord Full-width table with landscape orientation

Viewed 3822

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?

0 Answers
Related