Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/PhpWord/Style/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Table extends Border
const WIDTH_AUTO = 'auto'; // Automatically determined width
const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit)
const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip)
const STRETCH_AUTO = 'autofit'; // Automatically stretch the table to fit the page width
const STRETCH_FIXED = 'fixed'; // Do not stretch the table to fit the page width

/**
* Is this a first row style?
Expand Down Expand Up @@ -121,6 +123,11 @@ class Table extends Border
*/
private $unit = self::WIDTH_AUTO;

/**
* @var string Stretch the table to the page width
*/
private $stretch = self::STRETCH_AUTO;

/**
* Create new table style
*
Expand Down Expand Up @@ -563,6 +570,32 @@ public function setUnit($value = null)
return $this;
}

/**
* Get stretch
*
* @return string
*/
public function getStretch()
{
return $this->stretch;
}

/**
* Set stretch
*
* Stretch the table to the page width
*
* @param string $value
* @return self
*/
public function setStretch($value = null)
{
$enum = array(self::STRETCH_AUTO, self::STRETCH_FIXED);
$this->stretch = $this->setEnumVal($value, $enum, $this->stretch);

return $this;
}

/**
* Get table style only property by checking if it's a firstRow
*
Expand Down
15 changes: 15 additions & 0 deletions src/PhpWord/Writer/Word2007/Style/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private function writeStyle(XMLWriter $xmlWriter, TableStyle $style)
$styleWriter->write();

$this->writeWidth($xmlWriter, $style->getWidth(), $style->getUnit());
$this->writeLayout($xmlWriter, $style->getStretch());
$this->writeMargin($xmlWriter, $style);
$this->writeBorder($xmlWriter, $style);

Expand Down Expand Up @@ -104,6 +105,20 @@ private function writeWidth(XMLWriter $xmlWriter, $width, $unit)
$xmlWriter->endElement(); // w:tblW
}

/**
* Enable/Disable automatic resizing of the table
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $layout autofit / fixed
* @return void
*/
private function writeLayout(XMLWriter $xmlWriter, $stretch)
{
$xmlWriter->startElement('w:tblLayout');
$xmlWriter->writeAttribute('w:type', $stretch);
$xmlWriter->endElement(); // w:tblLayout
}

/**
* Write margin.
*
Expand Down