Merge Table and TableFull style

This commit is contained in:
Ivan Lanin 2014-03-24 11:33:20 +07:00
parent db57346c47
commit b24550d060
11 changed files with 769 additions and 1050 deletions

View File

@ -21,6 +21,7 @@ None yet.
- Use `PhpOffice\PhpWord` namespace for PSR compliance - @RomanSyroeshko @gabrielbull GH-159 GH-58
- Restructure folders and change folder name `Classes` to `src` and `Tests` to `test` for PSR compliance - @RomanSyroeshko @gabrielbull
- Compliance to phpDocumentor - @ivanlanin
- Merge Style\TableFull into Style\Table - @ivanlanin GH-160
## 0.8.1 - 17 Mar 2014

View File

@ -27,7 +27,7 @@ namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
use PhpOffice\PhpWord\Style\Table;
/**
* Style
@ -114,7 +114,7 @@ class Style
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new TableFull($styleTable, $styleFirstRow);
$style = new Table($styleTable, $styleFirstRow);
self::$_styleElements[$styleName] = $style;
}

View File

@ -30,6 +30,13 @@ namespace PhpOffice\PhpWord\Style;
*/
class Table
{
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\Table
*/
private $_firstRow = null;
/**
* Cell margin top
*
@ -59,14 +66,133 @@ class Table
private $_cellMarginBottom = null;
/**
* Create new table style
* Background color
*
* @var string
*/
public function __construct()
private $_bgColor;
/**
* Border size top
*
* @var int
*/
private $_borderTopSize;
/**
* Border color
*
* @var string top
*/
private $_borderTopColor;
/**
* Border size left
*
* @var int
*/
private $_borderLeftSize;
/**
* Border color left
*
* @var string
*/
private $_borderLeftColor;
/**
* Border size right
*
* @var int
*/
private $_borderRightSize;
/**
* Border color right
*
* @var string
*/
private $_borderRightColor;
/**
* Border size bottom
*
* @var int
*/
private $_borderBottomSize;
/**
* Border color bottom
*
* @var string
*/
private $_borderBottomColor;
/**
* Border size inside horizontal
*
* @var int
*/
private $_borderInsideHSize;
/**
* Border color inside horizontal
*
* @var string
*/
private $_borderInsideHColor;
/**
* Border size inside vertical
*
* @var int
*/
private $_borderInsideVSize;
/**
* Border color inside vertical
*
* @var string
*/
private $_borderInsideVColor;
/**
* Create new table style
*
* @param mixed $styleTable
* @param mixed $styleFirstRow
*/
public function __construct($styleTable = null, $styleFirstRow = null)
{
$this->_cellMarginTop = null;
$this->_cellMarginLeft = null;
$this->_cellMarginRight = null;
$this->_cellMarginBottom = null;
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
unset($this->_firstRow->_firstRow);
unset($this->_firstRow->_cellMarginBottom);
unset($this->_firstRow->_cellMarginTop);
unset($this->_firstRow->_cellMarginLeft);
unset($this->_firstRow->_cellMarginRight);
unset($this->_firstRow->_borderInsideVColor);
unset($this->_firstRow->_borderInsideVSize);
unset($this->_firstRow->_borderInsideHColor);
unset($this->_firstRow->_borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
}
}
/**
@ -77,7 +203,359 @@ class Table
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
if ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} elseif ($key == '_cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
}
}
/**
* Get First Row Style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getFirstRow()
{
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getLastRow()
{
return $this->_lastRow;
}
/**
* Get background
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getBgColor()
{
return $this->_bgColor;
}
/**
* Set background
*
* @param string $pValue
* @return \PhpOffice\PhpWord\Style\Table
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
}
/**
* Set TLRBVH Border Size
*
* @param int $pValue Border size in eighths of a point (1/8 point)
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
}
/**
* Get TLRBVH Border Size
*
* @return array
*/
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set TLRBVH Border Color
* @param string $pValue
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->_borderInsideHColor = $pValue;
$this->_borderInsideVColor = $pValue;
}
/**
* Get TLRB Border Color
*
* @return array
*/
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set border size top
*
* @param $pValue
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
/**
* Get border size top
*
* @return
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
/**
* Set border color top
*
* @param $pValue
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
/**
* Get border color top
*
* @return
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
/**
* Set border size left
*
* @param $pValue
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
/**
* Get border size left
*
* @return
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
/**
* Set border color left
*
* @param $pValue
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
/**
* Get border color left
*
* @return
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
/**
* Set border size right
*
* @param $pValue
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
/**
* Get border size right
*
* @return
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
/**
* Set border color right
*
* @param $pValue
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
/**
* Get border color right
*
* @return
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
/**
* Set border size bottom
*
* @param $pValue
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
/**
* Get border size bottom
*
* @return
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
/**
* Set border color bottom
*
* @param $pValue
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
/**
* Get border color bottom
*
* @return
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
/**
* Set border color inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHColor($pValue = null)
{
$this->_borderInsideHColor = $pValue;
}
/**
* Get border color inside horizontal
*
* @return
*/
public function getBorderInsideHColor()
{
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
}
/**
* Set border color inside vertical
*
* @param $pValue
*/
public function setBorderInsideVColor($pValue = null)
{
$this->_borderInsideVColor = $pValue;
}
/**
* Get border color inside vertical
*
* @return
*/
public function getBorderInsideVColor()
{
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
}
/**
* Set border size inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHSize($pValue = null)
{
$this->_borderInsideHSize = $pValue;
}
/**
* Get border size inside horizontal
*
* @return
*/
public function getBorderInsideHSize()
{
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
}
/**
* Set border size inside vertical
*
* @param $pValue
*/
public function setBorderInsideVSize($pValue = null)
{
$this->_borderInsideVSize = $pValue;
}
/**
* Get border size inside vertical
*
* @return
*/
public function getBorderInsideVSize()
{
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
}
/**

View File

@ -1,663 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
/**
* Table (full) style
*/
class TableFull
{
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\TableFull
*/
private $_firstRow = null;
/**
* Cell margin top
*
* @var int
*/
private $_cellMarginTop = null;
/**
* Cell margin left
*
* @var int
*/
private $_cellMarginLeft = null;
/**
* Cell margin right
*
* @var int
*/
private $_cellMarginRight = null;
/**
* Cell margin bottom
*
* @var int
*/
private $_cellMarginBottom = null;
/**
* Background color
*
* @var string
*/
private $_bgColor;
/**
* Border size top
*
* @var int
*/
private $_borderTopSize;
/**
* Border color
*
* @var string top
*/
private $_borderTopColor;
/**
* Border size left
*
* @var int
*/
private $_borderLeftSize;
/**
* Border color left
*
* @var string
*/
private $_borderLeftColor;
/**
* Border size right
*
* @var int
*/
private $_borderRightSize;
/**
* Border color right
*
* @var string
*/
private $_borderRightColor;
/**
* Border size bottom
*
* @var int
*/
private $_borderBottomSize;
/**
* Border color bottom
*
* @var string
*/
private $_borderBottomColor;
/**
* Border size inside horizontal
*
* @var int
*/
private $_borderInsideHSize;
/**
* Border color inside horizontal
*
* @var string
*/
private $_borderInsideHColor;
/**
* Border size inside vertical
*
* @var int
*/
private $_borderInsideVSize;
/**
* Border color inside vertical
*
* @var string
*/
private $_borderInsideVColor;
/**
* Create new table style
*
* @param mixed $styleTable
* @param mixed $styleFirstRow
*/
public function __construct($styleTable = null, $styleFirstRow = null)
{
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
unset($this->_firstRow->_firstRow);
unset($this->_firstRow->_cellMarginBottom);
unset($this->_firstRow->_cellMarginTop);
unset($this->_firstRow->_cellMarginLeft);
unset($this->_firstRow->_cellMarginRight);
unset($this->_firstRow->_borderInsideVColor);
unset($this->_firstRow->_borderInsideVSize);
unset($this->_firstRow->_borderInsideHColor);
unset($this->_firstRow->_borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
}
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
if ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} elseif ($key == '_cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
}
}
/**
* Get First Row Style
*
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function getFirstRow()
{
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function getLastRow()
{
return $this->_lastRow;
}
/**
* Get background
*
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function getBgColor()
{
return $this->_bgColor;
}
/**
* Set background
*
* @param string $pValue
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
}
/**
* Set TLRBVH Border Size
*
* @param int $pValue Border size in eighths of a point (1/8 point)
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
}
/**
* Get TLRBVH Border Size
*
* @return array
*/
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set TLRBVH Border Color
* @param string $pValue
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->_borderInsideHColor = $pValue;
$this->_borderInsideVColor = $pValue;
}
/**
* Get TLRB Border Color
*
* @return array
*/
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set border size top
*
* @param $pValue
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
/**
* Get border size top
*
* @return
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
/**
* Set border color top
*
* @param $pValue
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
/**
* Get border color top
*
* @return
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
/**
* Set border size left
*
* @param $pValue
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
/**
* Get border size left
*
* @return
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
/**
* Set border color left
*
* @param $pValue
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
/**
* Get border color left
*
* @return
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
/**
* Set border size right
*
* @param $pValue
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
/**
* Get border size right
*
* @return
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
/**
* Set border color right
*
* @param $pValue
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
/**
* Get border color right
*
* @return
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
/**
* Set border size bottom
*
* @param $pValue
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
/**
* Get border size bottom
*
* @return
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
/**
* Set border color bottom
*
* @param $pValue
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
/**
* Get border color bottom
*
* @return
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
/**
* Set border color inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHColor($pValue = null)
{
$this->_borderInsideHColor = $pValue;
}
/**
* Get border color inside horizontal
*
* @return
*/
public function getBorderInsideHColor()
{
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
}
/**
* Set border color inside vertical
*
* @param $pValue
*/
public function setBorderInsideVColor($pValue = null)
{
$this->_borderInsideVColor = $pValue;
}
/**
* Get border color inside vertical
*
* @return
*/
public function getBorderInsideVColor()
{
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
}
/**
* Set border size inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHSize($pValue = null)
{
$this->_borderInsideHSize = $pValue;
}
/**
* Get border size inside horizontal
*
* @return
*/
public function getBorderInsideHSize()
{
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
}
/**
* Set border size inside vertical
*
* @param $pValue
*/
public function setBorderInsideVSize($pValue = null)
{
$this->_borderInsideVSize = $pValue;
}
/**
* Get border size inside vertical
*
* @return
*/
public function getBorderInsideVSize()
{
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
}
/**
* Set cell margin top
*
* @param int $pValue
*/
public function setCellMarginTop($pValue = null)
{
$this->_cellMarginTop = $pValue;
}
/**
* Get cell margin top
*
* @return int
*/
public function getCellMarginTop()
{
return $this->_cellMarginTop;
}
/**
* Set cell margin left
*
* @param int $pValue
*/
public function setCellMarginLeft($pValue = null)
{
$this->_cellMarginLeft = $pValue;
}
/**
* Get cell margin left
*
* @return int
*/
public function getCellMarginLeft()
{
return $this->_cellMarginLeft;
}
/**
* Set cell margin right
*
* @param int $pValue
*/
public function setCellMarginRight($pValue = null)
{
$this->_cellMarginRight = $pValue;
}
/**
* Get cell margin right
*
* @return int
*/
public function getCellMarginRight()
{
return $this->_cellMarginRight;
}
/**
* Set cell margin bottom
*
* @param int $pValue
*/
public function setCellMarginBottom($pValue = null)
{
$this->_cellMarginBottom = $pValue;
}
/**
* Get cell margin bottom
*
* @return int
*/
public function getCellMarginBottom()
{
return $this->_cellMarginBottom;
}
/**
* Set TLRB cell margin
*
* @param int $pValue Margin in twips
*/
public function setCellMargin($pValue = null)
{
$this->_cellMarginTop = $pValue;
$this->_cellMarginLeft = $pValue;
$this->_cellMarginRight = $pValue;
$this->_cellMarginBottom = $pValue;
}
/**
* Get cell margin
*
* @return array
*/
public function getCellMargin()
{
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
}
}

View File

@ -30,7 +30,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
use PhpOffice\PhpWord\Style\Table;
/**
* ODText styloes part writer
@ -203,8 +203,8 @@ class Styles extends WriterPart
$xmlWriter->endElement();
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
// PhpOffice\PhpWord\Style\TableFull
} elseif ($style instanceof Table) {
// PhpOffice\PhpWord\Style\Table
}
}
}

View File

@ -575,7 +575,7 @@ class Base extends WriterPart
$tblStyle = $table->getStyle();
$tblWidth = $table->getWidth();
if ($tblStyle instanceof PhpOffice\PhpWord\Style\Table) {
$this->_writeTableStyle($xmlWriter, $tblStyle);
$this->_writeTableStyle($xmlWriter, $tblStyle, false);
} else {
if (!empty($tblStyle)) {
$xmlWriter->startElement('w:tblPr');
@ -679,52 +679,199 @@ class Base extends WriterPart
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Style\Table $style
* @param boolean $isFullStyle
*/
protected function _writeTableStyle(
XMLWriter $xmlWriter,
\PhpOffice\PhpWord\Style\Table $style = null
\PhpOffice\PhpWord\Style\Table $style,
$isFullStyle = true
) {
$margins = $style->getCellMargin();
$mTop = (!is_null($margins[0])) ? true : false;
$mLeft = (!is_null($margins[1])) ? true : false;
$mRight = (!is_null($margins[2])) ? true : false;
$mBottom = (!is_null($margins[3])) ? true : false;
$bgColor = $style->getBgColor();
$brdCol = $style->getBorderColor();
if ($mTop || $mLeft || $mRight || $mBottom) {
$brdSz = $style->getBorderSize();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$bInsH = (!is_null($brdSz[4])) ? true : false;
$bInsV = (!is_null($brdSz[5])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
$cellMargin = $style->getCellMargin();
$mTop = (!is_null($cellMargin[0])) ? true : false;
$mLeft = (!is_null($cellMargin[1])) ? true : false;
$mRight = (!is_null($cellMargin[2])) ? true : false;
$mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
if ($margins || $borders) {
$xmlWriter->startElement('w:tblPr');
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $margins[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
if ($margins) {
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $cellMargin[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $cellMargin[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $cellMargin[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $cellMargin[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $margins[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
if ($borders) {
$xmlWriter->startElement('w:tblBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
if ($bInsH) {
$xmlWriter->startElement('w:insideH');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[4]);
$xmlWriter->writeAttribute('w:color', $brdCol[4]);
$xmlWriter->endElement();
}
if ($bInsV) {
$xmlWriter->startElement('w:insideV');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[5]);
$xmlWriter->writeAttribute('w:color', $brdCol[5]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $margins[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement(); // w:tblPr
}
// Only write background color and first row for full style
if ($isFullStyle) {
// Background color
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:tcPr');
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $margins[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow);
}
}
}
$xmlWriter->endElement();
/**
* Write row style
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type
* @param PhpOffice\PhpWord\Style\Table $style
*/
protected function _writeRowStyle(
XMLWriter $xmlWriter,
$type,
\PhpOffice\PhpWord\Style\Table $style
) {
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type);
$xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:tcBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
/**

View File

@ -30,7 +30,6 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
/**
* Word2007 styles part writer
@ -72,7 +71,6 @@ class Styles extends Base
// Write DocDefaults
$this->_writeDocDefaults($xmlWriter);
// Write Style Definitions
$styles = Style::getStyles();
@ -170,7 +168,7 @@ class Styles extends Base
$this->_writeParagraphStyle($xmlWriter, $style);
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
} elseif ($style instanceof \PhpOffice\PhpWord\Style\Table) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1');
@ -184,9 +182,9 @@ class Styles extends Base
$xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement();
$this->_writeFullTableStyle($xmlWriter, $style);
$this->_writeTableStyle($xmlWriter, $style);
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:style
}
}
}
@ -197,200 +195,6 @@ class Styles extends Base
return $xmlWriter->getData();
}
/**
* Write table style
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Style\TableFull $style
*/
private function _writeFullTableStyle(XMLWriter $xmlWriter, TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$cellMargin = $style->getCellMargin();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$bInsH = (!is_null($brdSz[4])) ? true : false;
$bInsV = (!is_null($brdSz[5])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
$mTop = (!is_null($cellMargin[0])) ? true : false;
$mLeft = (!is_null($cellMargin[1])) ? true : false;
$mRight = (!is_null($cellMargin[2])) ? true : false;
$mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
$xmlWriter->startElement('w:tblPr');
if ($margins) {
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $cellMargin[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $cellMargin[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $cellMargin[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $cellMargin[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($borders) {
$xmlWriter->startElement('w:tblBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
if ($bInsH) {
$xmlWriter->startElement('w:insideH');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[4]);
$xmlWriter->writeAttribute('w:color', $brdCol[4]);
$xmlWriter->endElement();
}
if ($bInsV) {
$xmlWriter->startElement('w:insideV');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[5]);
$xmlWriter->writeAttribute('w:color', $brdCol[5]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
$xmlWriter->endElement();
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:tcPr');
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow);
}
}
/**
* Write first row style
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type
* @param PhpOffice\PhpWord\Style\TableFull $style
*/
private function _writeRowStyle(XMLWriter $xmlWriter, $type, TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type);
$xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:tcBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
/**
* Write document defaults
*

View File

@ -101,7 +101,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
$styles = array(
'Paragraph' => 'Paragraph',
'Font' => 'Font',
'Table' => 'TableFull',
'Table' => 'Table',
'Link' => 'Font',
);
foreach ($styles as $key => $value) {

View File

@ -1,130 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\TableFull;
/**
* @runTestsInSeparateProcesses
*/
class TableFullTest extends \PHPUnit_Framework_TestCase
{
/**
* Test class construction
*
* There are 3 variables for class constructor:
* - $styleTable: Define table styles
* - $styleFirstRow: Define style for the first row
* - $styleLastRow: Define style for the last row (reserved)
*/
public function testConstruct()
{
$styleTable = array('bgColor' => 'FF0000');
$styleFirstRow = array('borderBottomSize' => 3);
$object = new TableFull($styleTable, $styleFirstRow);
$this->assertEquals('FF0000', $object->getBgColor());
$firstRow = $object->getFirstRow();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TableFull', $firstRow);
$this->assertEquals(3, $firstRow->getBorderBottomSize());
}
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new TableFull();
$attributes = array(
'bgColor' => 'FF0000',
'borderTopSize' => 4,
'borderTopColor' => 'FF0000',
'borderLeftSize' => 4,
'borderLeftColor' => 'FF0000',
'borderRightSize' => 4,
'borderRightColor' => 'FF0000',
'borderBottomSize' => 4,
'borderBottomColor' => 'FF0000',
'borderInsideHSize' => 4,
'borderInsideHColor' => 'FF0000',
'borderInsideVSize' => 4,
'borderInsideVColor' => 'FF0000',
'cellMarginTop' => 240,
'cellMarginLeft' => 240,
'cellMarginRight' => 240,
'cellMarginBottom' => 240,
);
foreach ($attributes as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test border color
*
* Set border color and test if each part has the same color
* While looping, push values array to be asserted with getBorderColor
*/
public function testBorderColor()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 'FF0000';
$object->setBorderColor($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Color";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderColor());
}
/**
* Test border size
*
* Set border size and test if each part has the same size
* While looping, push values array to be asserted with getBorderSize
* Value is in eights of a point, i.e. 4 / 8 = .5pt
*/
public function testBorderSize()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 4;
$object->setBorderSize($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Size";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderSize());
}
/**
* Test cell margin
*
* Set cell margin and test if each part has the same margin
* While looping, push values array to be asserted with getCellMargin
* Value is in twips
*/
public function testCellMargin()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom');
$value = 240;
$object->setCellMargin($value);
foreach ($parts as $part) {
$get = "getCellMargin{$part}";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getCellMargin());
}
}

View File

@ -9,38 +9,120 @@ use PhpOffice\PhpWord\Style\Table;
class TableTest extends \PHPUnit_Framework_TestCase
{
/**
* Test set style value
* Test class construction
*
* There are 3 variables for class constructor:
* - $styleTable: Define table styles
* - $styleFirstRow: Define style for the first row
* - $styleLastRow: Define style for the last row (reserved)
*/
public function testSetStyleValue()
public function testConstruct()
{
$styleTable = array('bgColor' => 'FF0000');
$styleFirstRow = array('borderBottomSize' => 3);
$object = new Table($styleTable, $styleFirstRow);
$this->assertEquals('FF0000', $object->getBgColor());
$firstRow = $object->getFirstRow();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $firstRow);
$this->assertEquals(3, $firstRow->getBorderBottomSize());
}
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new Table();
$parts = array('Top', 'Left', 'Right', 'Bottom');
$value = 240; // In twips
foreach ($parts as $part) {
$property = "_cellMargin{$part}";
$get = "getCellMargin{$part}";
$object->setStyleValue($property, $value);
$attributes = array(
'bgColor' => 'FF0000',
'borderTopSize' => 4,
'borderTopColor' => 'FF0000',
'borderLeftSize' => 4,
'borderLeftColor' => 'FF0000',
'borderRightSize' => 4,
'borderRightColor' => 'FF0000',
'borderBottomSize' => 4,
'borderBottomColor' => 'FF0000',
'borderInsideHSize' => 4,
'borderInsideHColor' => 'FF0000',
'borderInsideVSize' => 4,
'borderInsideVColor' => 'FF0000',
'cellMarginTop' => 240,
'cellMarginLeft' => 240,
'cellMarginRight' => 240,
'cellMarginBottom' => 240,
);
foreach ($attributes as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test border color
*
* Set border color and test if each part has the same color
* While looping, push values array to be asserted with getBorderColor
*/
public function testBorderColor()
{
$object = new Table();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 'FF0000';
$object->setBorderColor($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Color";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderColor());
}
/**
* Test border size
*
* Set border size and test if each part has the same size
* While looping, push values array to be asserted with getBorderSize
* Value is in eights of a point, i.e. 4 / 8 = .5pt
*/
public function testBorderSize()
{
$object = new Table();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 4;
$object->setBorderSize($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Size";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderSize());
}
/**
* Test cell margin
*
* Set cell margin and test if each part has the same margin
* While looping, push values array to be asserted with getCellMargin
* Value is in twips
*/
public function testCellMargin()
{
$object = new Table();
$parts = array('Top', 'Left', 'Right', 'Bottom');
// Set cell margin and test if each part has the same margin
// While looping, push values array to be asserted with getCellMargin
$value = 240; // In twips
$value = 240;
$object->setCellMargin($value);
foreach ($parts as $part) {
$set = "setCellMargin{$part}";
$get = "getCellMargin{$part}";
$values[] = $value;
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getCellMargin());

View File

@ -21,7 +21,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase
$font = array('italic' => true);
$table = array('bgColor' => 'CCCCCC');
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Link' => 'Font', 'Table' => 'TableFull',
'Link' => 'Font', 'Table' => 'Table',
'Heading_1' => 'Font', 'Normal' => 'Paragraph');
$elementCount = 6;
Style::addParagraphStyle('Paragraph', $paragraph);