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 <julien.carignan@hotmail.com>
This commit is contained in:
Julien Carignan 2014-03-24 13:50:37 -04:00
parent 27840ab710
commit e990c77b47
3 changed files with 28 additions and 4 deletions

View File

@ -101,9 +101,9 @@ class PHPWord_Section_Table
* @param int $height * @param int $height
* @param mixed $style * @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; $this->_rows[] = $row;
return $row; return $row;
} }

View File

@ -37,7 +37,14 @@ class PHPWord_Section_Table_Row
* @var int * @var int
*/ */
private $_height = null; private $_height = null;
/**
* Row heightRules
*
* @var array
*/
private $_heightRules = array();
/** /**
* Row style * Row style
* *
@ -75,11 +82,12 @@ class PHPWord_Section_Table_Row
* @param int $height * @param int $height
* @param mixed $style * @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->_insideOf = $insideOf;
$this->_pCount = $pCount; $this->_pCount = $pCount;
$this->_height = $height; $this->_height = $height;
$this->_heightRules = $hRules;
$this->_style = new PHPWord_Style_Row(); $this->_style = new PHPWord_Style_Row();
if (!is_null($style)) { if (!is_null($style)) {
@ -138,4 +146,14 @@ class PHPWord_Section_Table_Row
{ {
return $this->_height; return $this->_height;
} }
/**
* Get all row height rules
*
* @return array
*/
public function getHeightRules()
{
return $this->_heightRules;
}
} }

View File

@ -570,6 +570,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
for ($i = 0; $i < $_cRows; $i++) { for ($i = 0; $i < $_cRows; $i++) {
$row = $_rows[$i]; $row = $_rows[$i];
$height = $row->getHeight(); $height = $row->getHeight();
$heightRules = $row->getHeightRules();
$rowStyle = $row->getStyle(); $rowStyle = $row->getStyle();
$tblHeader = $rowStyle->getTblHeader(); $tblHeader = $rowStyle->getTblHeader();
$cantSplit = $rowStyle->getCantSplit(); $cantSplit = $rowStyle->getCantSplit();
@ -580,6 +581,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->startElement('w:trPr'); $objWriter->startElement('w:trPr');
if (!is_null($height)) { if (!is_null($height)) {
$objWriter->startElement('w:trHeight'); $objWriter->startElement('w:trHeight');
if(!is_null($heightRules)) {
$objWriter->startAttribute('w:hRule');
$objWriter->text($heightRules);
$objWriter->endAttribute();
}
$objWriter->writeAttribute('w:val', $height); $objWriter->writeAttribute('w:val', $height);
$objWriter->endElement(); $objWriter->endElement();
} }