137 lines
2.3 KiB
PHP
Raw Normal View History

2012-05-06 18:25:40 +02:00
<?php
/**
* PHPWord
2012-05-06 18:25:40 +02:00
*
2014-03-27 23:55:06 +07:00
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Element\Row;
2014-04-03 08:44:41 +07:00
use PhpOffice\PhpWord\Style\Table as TableStyle;
2014-04-03 09:20:21 +07:00
/**
* Table element
*/
2014-04-03 08:44:41 +07:00
class Table extends Element
{
/**
* Table style
*
2014-04-03 08:44:41 +07:00
* @var TableStyle
*/
2014-04-03 08:44:41 +07:00
private $style;
/**
* Table rows
*
* @var array
*/
2014-04-03 08:44:41 +07:00
private $rows = array();
/**
* Table holder
*
* @var string
*/
2014-04-03 08:44:41 +07:00
private $docPart = null;
/**
* Table holder count
*
* @var int
*/
2014-04-03 08:44:41 +07:00
private $docPartId;
/**
* Table width
*
* @var int
*/
2014-04-03 08:44:41 +07:00
private $width = null;
/**
* Create a new table
*
2014-04-03 08:44:41 +07:00
* @param string $docPart
* @param int $docPartId
* @param mixed $style
*/
2014-04-03 08:44:41 +07:00
public function __construct($docPart, $docPartId, $style = null)
{
2014-04-03 08:44:41 +07:00
$this->docPart = $docPart;
$this->docPartId = $docPartId;
$this->style = $this->setStyle(new TableStyle(), $style);
}
/**
* Add a row
*
* @param int $height
2014-03-17 07:26:25 +07:00
* @param mixed $style
*/
public function addRow($height = null, $style = null)
{
2014-04-03 08:44:41 +07:00
$row = new Row($this->docPart, $this->docPartId, $height, $style);
$this->rows[] = $row;
return $row;
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
2014-04-03 08:44:41 +07:00
$i = count($this->rows) - 1;
$cell = $this->rows[$i]->addCell($width, $style);
return $cell;
}
/**
* Get all rows
*
* @return array
*/
public function getRows()
{
2014-04-03 08:44:41 +07:00
return $this->rows;
}
/**
* Get table style
*
2014-04-03 08:44:41 +07:00
* @return TableStyle
*/
public function getStyle()
{
2014-04-03 08:44:41 +07:00
return $this->style;
}
/**
* Set table width
*
2014-03-17 07:26:25 +07:00
* @param int $width
*/
public function setWidth($width)
{
2014-04-03 08:44:41 +07:00
$this->width = $width;
}
/**
* Get table width
*
* @return int
*/
public function getWidth()
{
2014-04-03 08:44:41 +07:00
return $this->width;
}
2012-05-06 18:25:40 +02:00
}