2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
namespace PhpOffice\PhpWord\Element;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-04-03 08:44:41 +07:00
|
|
|
use PhpOffice\PhpWord\Style\Table as TableStyle;
|
2014-04-03 09:20:21 +07:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Table element
|
|
|
|
|
*/
|
2014-04-08 00:23:49 +07:00
|
|
|
class Table extends AbstractElement
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2013-12-11 14:45:44 -05:00
|
|
|
/**
|
|
|
|
|
* Table style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @var \PhpOffice\PhpWord\Style\Table
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
private $style;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Table rows
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
private $rows = array();
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-01-13 23:14:05 +07:00
|
|
|
/**
|
|
|
|
|
* Table width
|
|
|
|
|
*
|
2014-04-11 23:02:05 +07:00
|
|
|
* @var integer
|
2014-01-13 23:14:05 +07:00
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
private $width = null;
|
2014-01-13 23:14:05 +07:00
|
|
|
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
2013-12-11 14:45:44 -05:00
|
|
|
* @param mixed $style
|
|
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
public function __construct($docPart, $docPartId, $style = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-04-05 00:08:00 +07:00
|
|
|
$this->setDocPart($docPart, $docPartId);
|
2014-04-03 08:44:41 +07:00
|
|
|
$this->style = $this->setStyle(new TableStyle(), $style);
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-02-22 11:01:15 +07:00
|
|
|
public function addRow($height = null, $style = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-04-05 00:08:00 +07:00
|
|
|
$row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
|
2014-05-04 00:57:44 +07:00
|
|
|
$row->setPhpWord($this->phpWord);
|
2014-04-03 08:44:41 +07:00
|
|
|
$this->rows[] = $row;
|
2014-02-22 11:01:15 +07:00
|
|
|
return $row;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a cell
|
|
|
|
|
*
|
2014-04-11 23:02:05 +07:00
|
|
|
* @param integer $width
|
2013-12-11 14:45:44 -05:00
|
|
|
* @param mixed $style
|
2014-04-08 16:09:31 +07:00
|
|
|
* @return Cell
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-01-13 23:14:05 +07:00
|
|
|
public function addCell($width = null, $style = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-04-22 17:25:10 +07:00
|
|
|
$index = count($this->rows) - 1;
|
|
|
|
|
$cell = $this->rows[$index]->addCell($width, $style);
|
2013-12-11 14:45:44 -05:00
|
|
|
return $cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all rows
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getRows()
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
return $this->rows;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get table style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Style\Table
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
public function getStyle()
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
return $this->style;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2014-01-13 23:14:05 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set table width
|
|
|
|
|
*
|
2014-04-11 23:02:05 +07:00
|
|
|
* @param integer $width
|
2014-01-13 23:14:05 +07:00
|
|
|
*/
|
|
|
|
|
public function setWidth($width)
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
$this->width = $width;
|
2014-01-13 23:14:05 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get table width
|
|
|
|
|
*
|
2014-04-11 23:02:05 +07:00
|
|
|
* @return integer
|
2014-01-13 23:14:05 +07:00
|
|
|
*/
|
|
|
|
|
public function getWidth()
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
return $this->width;
|
2014-01-13 23:14:05 +07:00
|
|
|
}
|
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
|
|
|
}
|