From 27840ab7103f4bd46190891c5d80b9f5a2393077 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Mon, 24 Mar 2014 13:43:20 -0400 Subject: [PATCH 1/8] Font-style addition: bgColor Signed-off-by: Julien Carignan --- Classes/PHPWord/Style/Font.php | 34 ++++++++++++++++++++++++ Classes/PHPWord/Writer/Word2007/Base.php | 10 +++++++ 2 files changed, 44 insertions(+) diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index 2aa6cbc6d3..66d8283213 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -149,6 +149,18 @@ class PHPWord_Style_Font * @var string */ private $_fgColor = null; + + /** + * Background color + * + * @var string + */ + private $_bgColor = null; + /** + * Text line height + * + * @var int + */ /** * Text line height @@ -468,6 +480,28 @@ public function setFgColor($pValue = null) $this->_fgColor = $pValue; return $this; } + + /** + * Get background color + * + * @return string + */ + public function getBgColor() + { + return $this->_bgColor; + } + + /** + * Set background color + * + * @param string $pValue + * @return PHPWord_Style_Font + */ + public function setBgColor($pValue = null) + { + $this->_bgColor = $pValue; + return $this; + } /** * Get style type diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index d829bf9299..0102979d8c 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -398,6 +398,7 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $color = $style->getColor(); $size = $style->getSize(); $fgColor = $style->getFgColor(); + $bgColor = $style->getBgColor(); $strikethrough = $style->getStrikethrough(); $underline = $style->getUnderline(); $superscript = $style->getSuperScript(); @@ -467,6 +468,15 @@ protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, P $objWriter->writeAttribute('w:val', $fgColor); $objWriter->endElement(); } + + // Background-Color + if (!is_null($bgColor)) { + $objWriter->startElement('w:shd'); + $objWriter->writeAttribute('w:val', "clear"); + $objWriter->writeAttribute('w:color', "auto"); + $objWriter->writeAttribute('w:fill', $bgColor); + $objWriter->endElement(); + } // Superscript/subscript if ($superscript || $subscript) { From e990c77b474aa39bdf6e883a9065d4794e6a2379 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Mon, 24 Mar 2014 13:50:37 -0400 Subject: [PATCH 2/8] Added height rules for table row - mostly for removing the added space after a table - Code mostly come from this discussion: https://phpword.codeplex.com/discussions/440933 - Usage: $table->addRow(5000, $rowStyle, "exact"); Signed-off-by: Julien Carignan --- Classes/PHPWord/Section/Table.php | 4 ++-- Classes/PHPWord/Section/Table/Row.php | 22 ++++++++++++++++++++-- Classes/PHPWord/Writer/Word2007/Base.php | 6 ++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Classes/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php index 80126cba7b..7efdf0b87c 100755 --- a/Classes/PHPWord/Section/Table.php +++ b/Classes/PHPWord/Section/Table.php @@ -101,9 +101,9 @@ public function __construct($insideOf, $pCount, $style = null) * @param int $height * @param mixed $style */ - public function addRow($height = null, $style = null) + public function addRow($height = null, $style = null, $hRules = null) { - $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style); + $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style, $hRules); $this->_rows[] = $row; return $row; } diff --git a/Classes/PHPWord/Section/Table/Row.php b/Classes/PHPWord/Section/Table/Row.php index dd8ea65c12..5b239c894d 100644 --- a/Classes/PHPWord/Section/Table/Row.php +++ b/Classes/PHPWord/Section/Table/Row.php @@ -37,7 +37,14 @@ class PHPWord_Section_Table_Row * @var int */ private $_height = null; - + + /** + * Row heightRules + * + * @var array + */ + private $_heightRules = array(); + /** * Row style * @@ -75,11 +82,12 @@ class PHPWord_Section_Table_Row * @param int $height * @param mixed $style */ - public function __construct($insideOf, $pCount, $height = null, $style = null) + public function __construct($insideOf, $pCount, $height = null, $style = null, $hRules = null) { $this->_insideOf = $insideOf; $this->_pCount = $pCount; $this->_height = $height; + $this->_heightRules = $hRules; $this->_style = new PHPWord_Style_Row(); if (!is_null($style)) { @@ -138,4 +146,14 @@ public function getHeight() { return $this->_height; } + + /** + * Get all row height rules + * + * @return array + */ + public function getHeightRules() + { + return $this->_heightRules; + } } diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 0102979d8c..57bb72663a 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -570,6 +570,7 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo for ($i = 0; $i < $_cRows; $i++) { $row = $_rows[$i]; $height = $row->getHeight(); + $heightRules = $row->getHeightRules(); $rowStyle = $row->getStyle(); $tblHeader = $rowStyle->getTblHeader(); $cantSplit = $rowStyle->getCantSplit(); @@ -580,6 +581,11 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->startElement('w:trPr'); if (!is_null($height)) { $objWriter->startElement('w:trHeight'); + if(!is_null($heightRules)) { + $objWriter->startAttribute('w:hRule'); + $objWriter->text($heightRules); + $objWriter->endAttribute(); + } $objWriter->writeAttribute('w:val', $height); $objWriter->endElement(); } From e2cdf434ba315009b3eb5f32509477020d814209 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Mon, 24 Mar 2014 13:55:01 -0400 Subject: [PATCH 3/8] "php://output" content-length + tmpfile location - added content-length header to know the total file size during the download - Tmp file should go into sys_get_temp_dir() instead of "./" Signed-off-by: Julien Carignan --- Classes/PHPWord/Writer/Word2007.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index 16d66c666f..2589e9efd7 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -113,7 +113,7 @@ public function save($pFilename = null) // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { - $pFilename = @tempnam('./', 'phppttmp'); + $pFilename = @tempnam(sys_get_temp_dir(), 'phpword_');// temp files should go to system temp directory (if a user cancels a download, the file stays) if ($pFilename == '') { $pFilename = $originalFilename; } @@ -236,6 +236,7 @@ public function save($pFilename = null) // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { + header('Content-Length: '.filesize($pFilename));// if php://output, we want to know the total file size when downloading if (copy($pFilename, $originalFilename) === false) { throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename."); } From 6796883d43f5cecd43844204926ab048bb4be6ef Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Mon, 24 Mar 2014 14:03:02 -0400 Subject: [PATCH 4/8] added samples for bgColor and tableRowHeightRules Signed-off-by: Julien Carignan --- samples/Sample_20_BGColor.php | 30 ++++++++++++++++++++ samples/Sample_21_TableRowRules.php | 44 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 samples/Sample_20_BGColor.php create mode 100644 samples/Sample_21_TableRowRules.php diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php new file mode 100644 index 0000000000..1122ba3d8a --- /dev/null +++ b/samples/Sample_20_BGColor.php @@ -0,0 +1,30 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word Document +echo date('H:i:s') , ' Create new PHPWord object' , EOL; +$PHPWord = new PHPWord(); +$section = $PHPWord->createSection(); + +$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => PHPWord_Style_Font::FGCOLOR_YELLOW)); +$section->addText("This one uses bgColor and is using hex value (0xfbbb10)", array("bgColor" => "fbbb10")); +$section->addText("Compatible with font colors", array("color"=>"0000ff", "bgColor" => "fbbb10")); + + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php new file mode 100644 index 0000000000..83d03e0c05 --- /dev/null +++ b/samples/Sample_21_TableRowRules.php @@ -0,0 +1,44 @@ +'); +require_once '../Classes/PHPWord.php'; + +// New Word Document +echo date('H:i:s') , ' Create new PHPWord object' , EOL; +$PHPWord = new PHPWord(); +$section = $PHPWord->createSection(); + +$section->addText("By default, a table row adds a textbreak after its content (notice the red border), even if the row height is <= height of the content"); + +$table1 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0)); +$table1->addRow(3750); +$cell1 = $table1->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "ff0000")); +$cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center")); + +$section->addTextBreak(); +$section->addText("But if we set the row rule \"exact\", we get rid of the textbreak!"); + +$table2 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0)); +$table2->addRow(3750, null, "exact"); +$cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00")); +$cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center")); + +$section->addTextBreak(); +$section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips."); +$section->addText("So: $"."table2->addRow(3750, null, 'exact');"); + +// Save file +$name = basename(__FILE__, '.php'); +$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); +foreach ($writers as $writer => $extension) { + echo date('H:i:s'), " Write to {$writer} format", EOL; + $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); + $objWriter->save("{$name}.{$extension}"); + rename("{$name}.{$extension}", "results/{$name}.{$extension}"); +} + + +// Done +echo date('H:i:s'), " Done writing file(s)", EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; From 8363ee27d1461177dd625974f43feb1c160eb6ba Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Fri, 28 Mar 2014 13:26:36 -0400 Subject: [PATCH 5/8] table row height rule moved to rowStyle (ivanlanin) new usage: $table->addRow($height, array("heightRule"=>"exact")); Signed-off-by: Julien Carignan --- Classes/PHPWord/Section/Table.php | 4 +-- Classes/PHPWord/Section/Table/Row.php | 20 +-------------- Classes/PHPWord/Style/Row.php | 32 ++++++++++++++++++++++++ Classes/PHPWord/Writer/Word2007/Base.php | 8 +++--- samples/Sample_21_TableRowRules.php | 11 +++++--- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/Classes/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php index 7efdf0b87c..80126cba7b 100755 --- a/Classes/PHPWord/Section/Table.php +++ b/Classes/PHPWord/Section/Table.php @@ -101,9 +101,9 @@ public function __construct($insideOf, $pCount, $style = null) * @param int $height * @param mixed $style */ - public function addRow($height = null, $style = null, $hRules = null) + public function addRow($height = null, $style = null) { - $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style, $hRules); + $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style); $this->_rows[] = $row; return $row; } diff --git a/Classes/PHPWord/Section/Table/Row.php b/Classes/PHPWord/Section/Table/Row.php index 5b239c894d..7ca99823e6 100644 --- a/Classes/PHPWord/Section/Table/Row.php +++ b/Classes/PHPWord/Section/Table/Row.php @@ -38,13 +38,6 @@ class PHPWord_Section_Table_Row */ private $_height = null; - /** - * Row heightRules - * - * @var array - */ - private $_heightRules = array(); - /** * Row style * @@ -82,12 +75,11 @@ class PHPWord_Section_Table_Row * @param int $height * @param mixed $style */ - public function __construct($insideOf, $pCount, $height = null, $style = null, $hRules = null) + public function __construct($insideOf, $pCount, $height = null, $style = null) { $this->_insideOf = $insideOf; $this->_pCount = $pCount; $this->_height = $height; - $this->_heightRules = $hRules; $this->_style = new PHPWord_Style_Row(); if (!is_null($style)) { @@ -146,14 +138,4 @@ public function getHeight() { return $this->_height; } - - /** - * Get all row height rules - * - * @return array - */ - public function getHeightRules() - { - return $this->_heightRules; - } } diff --git a/Classes/PHPWord/Style/Row.php b/Classes/PHPWord/Style/Row.php index da039d84b5..aae7e8519d 100644 --- a/Classes/PHPWord/Style/Row.php +++ b/Classes/PHPWord/Style/Row.php @@ -45,6 +45,13 @@ class PHPWord_Style_Row */ private $_cantSplit = false; + /** + * Table row height rule (auto, exact, atLeast) + * + * @var String + */ + private $_heightRule = null; + /** * Create a new row style */ @@ -112,4 +119,29 @@ public function getCantSplit() { return $this->_cantSplit; } + + /** + * Set heightRule + * + * @param String $pValue + * @return PHPWord_Style_Row + */ + public function setHeightRule($pValue = false) + { + if (!is_string($pValue)) { + $pValue = null; + } + $this->_heightRule = $pValue; + return $this; + } + + /** + * Get heightRule + * + * @return heightRule + */ + public function getHeightRule() + { + return $this->_heightRule; + } } diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 57bb72663a..0a45fb2094 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -569,11 +569,11 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo for ($i = 0; $i < $_cRows; $i++) { $row = $_rows[$i]; - $height = $row->getHeight(); - $heightRules = $row->getHeightRules(); + $height = $row->getHeight(); $rowStyle = $row->getStyle(); $tblHeader = $rowStyle->getTblHeader(); $cantSplit = $rowStyle->getCantSplit(); + $heightRule = $rowStyle->getHeightRule(); $objWriter->startElement('w:tr'); @@ -581,9 +581,9 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->startElement('w:trPr'); if (!is_null($height)) { $objWriter->startElement('w:trHeight'); - if(!is_null($heightRules)) { + if(!is_null($heightRule)) { $objWriter->startAttribute('w:hRule'); - $objWriter->text($heightRules); + $objWriter->text($heightRule); $objWriter->endAttribute(); } $objWriter->writeAttribute('w:val', $height); diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php index 83d03e0c05..18c67be3ec 100644 --- a/samples/Sample_21_TableRowRules.php +++ b/samples/Sample_21_TableRowRules.php @@ -9,7 +9,9 @@ $PHPWord = new PHPWord(); $section = $PHPWord->createSection(); -$section->addText("By default, a table row adds a textbreak after its content (notice the red border), even if the row height is <= height of the content"); +$section->addText("By default, when you insert an image, it adds a textbreak after its content."); +$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell"); +$section->addText("On the image with the red border, even if we set the row height to the height of the image, the textbreak is still there:"); $table1 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0)); $table1->addRow(3750); @@ -17,16 +19,17 @@ $cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center")); $section->addTextBreak(); -$section->addText("But if we set the row rule \"exact\", we get rid of the textbreak!"); +$section->addText("But if we set the rowStyle hRule \"exact\", the real row height is used, removing the textbreak:"); $table2 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0)); -$table2->addRow(3750, null, "exact"); +$table2->addRow(3750, array("heightRule"=>"exact")); $cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00")); $cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center")); $section->addTextBreak(); $section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips."); -$section->addText("So: $"."table2->addRow(3750, null, 'exact');"); +$section->addText("So: $"."table2->addRow(3750, array('heightRule'=>'exact'));"); +$section->addText("heightRule defaults to 'atLeast' when the row has an height set, and default to 'auto' otherwise"); // Save file $name = basename(__FILE__, '.php'); From 9faaa1b566b418577d56b4fe15cb461d4d234a35 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Fri, 28 Mar 2014 13:31:30 -0400 Subject: [PATCH 6/8] reverted table/row Signed-off-by: Julien Carignan --- Classes/PHPWord/Section/Table/Row.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PHPWord/Section/Table/Row.php b/Classes/PHPWord/Section/Table/Row.php index 7ca99823e6..dd8ea65c12 100644 --- a/Classes/PHPWord/Section/Table/Row.php +++ b/Classes/PHPWord/Section/Table/Row.php @@ -37,7 +37,7 @@ class PHPWord_Section_Table_Row * @var int */ private $_height = null; - + /** * Row style * From 772017d8e3ede9c308104d237ba5b7e41b57d2e1 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Fri, 28 Mar 2014 13:33:49 -0400 Subject: [PATCH 7/8] empty space remove --- Classes/PHPWord/Writer/Word2007/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 0a45fb2094..16680ae2ec 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -569,7 +569,7 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo for ($i = 0; $i < $_cRows; $i++) { $row = $_rows[$i]; - $height = $row->getHeight(); + $height = $row->getHeight(); $rowStyle = $row->getStyle(); $tblHeader = $rowStyle->getTblHeader(); $cantSplit = $rowStyle->getCantSplit(); From 612ad857739ff7cdb6e26fbfa8585588e33a0596 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Fri, 28 Mar 2014 15:21:01 -0400 Subject: [PATCH 8/8] changed heightRule string to exactHeight bool --- Classes/PHPWord/Style/Row.php | 26 ++++++++++++------------ Classes/PHPWord/Writer/Word2007/Base.php | 6 +++--- samples/Sample_21_TableRowRules.php | 7 +++---- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Classes/PHPWord/Style/Row.php b/Classes/PHPWord/Style/Row.php index aae7e8519d..d779d3cc1d 100644 --- a/Classes/PHPWord/Style/Row.php +++ b/Classes/PHPWord/Style/Row.php @@ -46,11 +46,11 @@ class PHPWord_Style_Row private $_cantSplit = false; /** - * Table row height rule (auto, exact, atLeast) + * Table row exact height * - * @var String + * @var bool */ - private $_heightRule = null; + private $_exactHeight = false; /** * Create a new row style @@ -121,27 +121,27 @@ public function getCantSplit() } /** - * Set heightRule + * Set exactHeight * - * @param String $pValue + * @param bool $pValue * @return PHPWord_Style_Row */ - public function setHeightRule($pValue = false) + public function setExactHeight($pValue = false) { - if (!is_string($pValue)) { - $pValue = null; + if (!is_bool($pValue)) { + $pValue = false; } - $this->_heightRule = $pValue; + $this->_exactHeight = $pValue; return $this; } /** - * Get heightRule + * Get exactHeight * - * @return heightRule + * @return boolean */ - public function getHeightRule() + public function getExactHeight() { - return $this->_heightRule; + return $this->_exactHeight; } } diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index 16680ae2ec..1cf3bad394 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -573,7 +573,7 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $rowStyle = $row->getStyle(); $tblHeader = $rowStyle->getTblHeader(); $cantSplit = $rowStyle->getCantSplit(); - $heightRule = $rowStyle->getHeightRule(); + $exactHeight = $rowStyle->getExactHeight(); $objWriter->startElement('w:tr'); @@ -581,9 +581,9 @@ protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWo $objWriter->startElement('w:trPr'); if (!is_null($height)) { $objWriter->startElement('w:trHeight'); - if(!is_null($heightRule)) { + if($exactHeight) { $objWriter->startAttribute('w:hRule'); - $objWriter->text($heightRule); + $objWriter->text("exact"); $objWriter->endAttribute(); } $objWriter->writeAttribute('w:val', $height); diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php index 18c67be3ec..1082f99f86 100644 --- a/samples/Sample_21_TableRowRules.php +++ b/samples/Sample_21_TableRowRules.php @@ -19,17 +19,16 @@ $cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center")); $section->addTextBreak(); -$section->addText("But if we set the rowStyle hRule \"exact\", the real row height is used, removing the textbreak:"); +$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:"); $table2 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0)); -$table2->addRow(3750, array("heightRule"=>"exact")); +$table2->addRow(3750, array("exactHeight"=>)); $cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00")); $cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center")); $section->addTextBreak(); $section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips."); -$section->addText("So: $"."table2->addRow(3750, array('heightRule'=>'exact'));"); -$section->addText("heightRule defaults to 'atLeast' when the row has an height set, and default to 'auto' otherwise"); +$section->addText("So: $"."table2->addRow(3750, array('exactHeight'=>true));"); // Save file $name = basename(__FILE__, '.php');