table->setStretch() optionally avoids the table to stretch to the page width (only for word output)
This commit is contained in:
parent
38cb04d322
commit
133b727f59
|
|
@ -28,6 +28,8 @@ class Table extends Border
|
||||||
const WIDTH_AUTO = 'auto'; // Automatically determined width
|
const WIDTH_AUTO = 'auto'; // Automatically determined width
|
||||||
const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit)
|
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 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?
|
* Is this a first row style?
|
||||||
|
|
@ -121,6 +123,11 @@ class Table extends Border
|
||||||
*/
|
*/
|
||||||
private $unit = self::WIDTH_AUTO;
|
private $unit = self::WIDTH_AUTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Stretch the table to the page width
|
||||||
|
*/
|
||||||
|
private $stretch = self::STRETCH_AUTO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new table style
|
* Create new table style
|
||||||
*
|
*
|
||||||
|
|
@ -563,6 +570,32 @@ class Table extends Border
|
||||||
return $this;
|
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
|
* Get table style only property by checking if it's a firstRow
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ class Table extends AbstractStyle
|
||||||
$styleWriter->write();
|
$styleWriter->write();
|
||||||
|
|
||||||
$this->writeWidth($xmlWriter, $style->getWidth(), $style->getUnit());
|
$this->writeWidth($xmlWriter, $style->getWidth(), $style->getUnit());
|
||||||
|
$this->writeLayout($xmlWriter, $style->getStretch());
|
||||||
$this->writeMargin($xmlWriter, $style);
|
$this->writeMargin($xmlWriter, $style);
|
||||||
$this->writeBorder($xmlWriter, $style);
|
$this->writeBorder($xmlWriter, $style);
|
||||||
|
|
||||||
|
|
@ -104,6 +105,20 @@ class Table extends AbstractStyle
|
||||||
$xmlWriter->endElement(); // w:tblW
|
$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.
|
* Write margin.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue