143 lines
2.7 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 2010-2014 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Element;
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
*/
class Table extends AbstractElement
{
/**
* Table style
*
* @var \PhpOffice\PhpWord\Style\Table
*/
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 width
*
2014-04-11 23:02:05 +07:00
* @var integer
*/
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
2014-04-11 23:02:05 +07:00
* @param integer $docPartId
* @param mixed $style
*/
2014-04-03 08:44:41 +07:00
public function __construct($docPart, $docPartId, $style = null)
{
$this->setDocPart($docPart, $docPartId);
2014-04-03 08:44:41 +07:00
$this->style = $this->setStyle(new TableStyle(), $style);
}
/**
* Add a row
*
2014-04-11 23:02:05 +07:00
* @param integer $height
2014-03-17 07:26:25 +07:00
* @param mixed $style
*/
public function addRow($height = null, $style = null)
{
$row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
$row->setPhpWord($this->phpWord);
2014-04-03 08:44:41 +07:00
$this->rows[] = $row;
return $row;
}
/**
* Add a cell
*
2014-04-11 23:02:05 +07:00
* @param integer $width
* @param mixed $style
* @return Cell
*/
public function addCell($width = null, $style = null)
{
$index = count($this->rows) - 1;
$cell = $this->rows[$index]->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
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getStyle()
{
2014-04-03 08:44:41 +07:00
return $this->style;
}
/**
* Set table width
*
2014-04-11 23:02:05 +07:00
* @param integer $width
*/
public function setWidth($width)
{
2014-04-03 08:44:41 +07:00
$this->width = $width;
}
/**
* Get table width
*
2014-04-11 23:02:05 +07:00
* @return integer
*/
public function getWidth()
{
2014-04-03 08:44:41 +07:00
return $this->width;
}
2014-04-11 23:02:05 +07:00
/**
* Get column count
*
* @return integer
*/
public function countColumns()
{
$columnCount = 0;
if (is_array($this->rows)) {
$rowCount = count($this->rows);
for ($i = 0; $i < $rowCount; $i++) {
$cellCount = count($this->rows[$i]->getCells());
if ($columnCount < $cellCount) {
$columnCount = $cellCount;
}
}
}
return $columnCount;
}
2012-05-06 18:25:40 +02:00
}