From b3c5a76a64bc2f130d2c95c329b230354f21b3cc Mon Sep 17 00:00:00 2001 From: gianis6 Date: Thu, 27 Mar 2014 16:33:02 +0100 Subject: [PATCH] Update Base.php added tblGrid element so that LibreOffice and OpenOffice can size the tables columns properly --- src/PhpWord/Writer/Word2007/Base.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Base.php b/src/PhpWord/Writer/Word2007/Base.php index d76d543d..0f93f488 100644 --- a/src/PhpWord/Writer/Word2007/Base.php +++ b/src/PhpWord/Writer/Word2007/Base.php @@ -571,6 +571,30 @@ class Base extends WriterPart if ($_cRows > 0) { $xmlWriter->startElement('w:tbl'); + + $cellWidths = array(); + for($i=0; $i<$_cRows; $i++) + { + $row = $_rows[$i]; + $cells = $row->getCells(); + if(count($cells) <= count($cellWidths)) + continue; + + $cellWidths = array(); + foreach ($cells as $cell) + $cellWidths[] = $cell->getWidth(); + } + + $xmlWriter->startElement('w:tblGrid'); + foreach($cellWidths as $width) + { + $xmlWriter->startElement('w:gridCol'); + $xmlWriter->writeAttribute('w:w', $width); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + $tblStyle = $table->getStyle(); $tblWidth = $table->getWidth(); if ($tblStyle instanceof PhpOffice\PhpWord\Style\Table) {