table->setStretch() optionally avoids the table to stretch to the page width (only for word output)
This commit is contained in:
parent
e846602d1e
commit
7ddaed240f
|
|
@ -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?
|
||||
|
|
@ -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
|
||||
*
|
||||
|
|
@ -582,6 +589,32 @@ class Table extends Border
|
|||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class Table extends AbstractStyle
|
|||
}
|
||||
|
||||
$this->writeWidth($xmlWriter, $style->getWidth(), $style->getUnit());
|
||||
$this->writeLayout($xmlWriter, $style->getStretch());
|
||||
$this->writeMargin($xmlWriter, $style);
|
||||
$this->writeBorder($xmlWriter, $style);
|
||||
|
||||
|
|
@ -106,6 +107,20 @@ class Table extends AbstractStyle
|
|||
$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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue