From b9774cbf78afa657028b42ce1712f7a06e4b23b6 Mon Sep 17 00:00:00 2001 From: Evgenii Kopach Date: Fri, 9 Feb 2018 20:48:19 +0300 Subject: [PATCH 1/2] Added the function to fix the width of columns in tables, when text very long and without delimiters. --- src/PhpWord/Style/Table.php | 19 +++++++++++++++++++ src/PhpWord/Writer/Word2007/Style/Table.php | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index a3d454f3aa..c71d7f7b62 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -121,6 +121,13 @@ class Table extends Border */ private $unit = self::WIDTH_AUTO; + /** + * Fixes the width of columns with long text without delimiters + * + * @var bool + */ + private $fixedColsWidth = true; + /** * Create new table style * @@ -582,6 +589,18 @@ public function setUnit($value = null) return $this; } + public function setFixedColsWidth($value = true) + { + $this->cantSplit = $this->setBoolVal($value, $this->fixedColsWidth); + + return $this; + } + + public function isFixedColsWidth() + { + return $this->fixedColsWidth; + } + /** * Get table style only property by checking if it's a firstRow * diff --git a/src/PhpWord/Writer/Word2007/Style/Table.php b/src/PhpWord/Writer/Word2007/Style/Table.php index 620e4fbf62..19d9a2738b 100644 --- a/src/PhpWord/Writer/Word2007/Style/Table.php +++ b/src/PhpWord/Writer/Word2007/Style/Table.php @@ -76,6 +76,13 @@ private function writeStyle(XMLWriter $xmlWriter, TableStyle $style) $xmlWriter->endElement(); } + // Table fixed columns width + if ($style->isFixedColsWidth()) { + $xmlWriter->startElement('w:tblLayout'); + $xmlWriter->writeAttribute('w:type', 'fixed'); + $xmlWriter->endElement(); + } + $this->writeWidth($xmlWriter, $style->getWidth(), $style->getUnit()); $this->writeMargin($xmlWriter, $style); $this->writeBorder($xmlWriter, $style); From e57b70a8f30e0f1b606968da56295ea64afc85f5 Mon Sep 17 00:00:00 2001 From: Evgenii Kopach Date: Fri, 9 Feb 2018 23:14:40 +0300 Subject: [PATCH 2/2] Fix setFixedColsWidth method --- src/PhpWord/Style/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index c71d7f7b62..b7d778dc9c 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -591,7 +591,7 @@ public function setUnit($value = null) public function setFixedColsWidth($value = true) { - $this->cantSplit = $this->setBoolVal($value, $this->fixedColsWidth); + $this->fixedColsWidth = $this->setBoolVal($value, $this->fixedColsWidth); return $this; }