Table Row allows tblHeader and cantSplit
This commit is contained in:
parent
194940d478
commit
b0a24703f3
@ -45,13 +45,6 @@ class PHPWord_Section_Table
|
|||||||
*/
|
*/
|
||||||
private $_rows = array();
|
private $_rows = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Row heights
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $_rowHeights = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table holder
|
* Table holder
|
||||||
*
|
*
|
||||||
@ -107,10 +100,11 @@ class PHPWord_Section_Table
|
|||||||
*
|
*
|
||||||
* @param int $height
|
* @param int $height
|
||||||
*/
|
*/
|
||||||
public function addRow($height = null)
|
public function addRow($height = null, $style = null)
|
||||||
{
|
{
|
||||||
$this->_rows[] = array();
|
$row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style);
|
||||||
$this->_rowHeights[] = $height;
|
$this->_rows[] = $row;
|
||||||
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,9 +116,8 @@ class PHPWord_Section_Table
|
|||||||
*/
|
*/
|
||||||
public function addCell($width = null, $style = null)
|
public function addCell($width = null, $style = null)
|
||||||
{
|
{
|
||||||
$cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style);
|
|
||||||
$i = count($this->_rows) - 1;
|
$i = count($this->_rows) - 1;
|
||||||
$this->_rows[$i][] = $cell;
|
$cell = $this->_rows[$i]->addCell($width, $style);
|
||||||
return $cell;
|
return $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,16 +131,6 @@ class PHPWord_Section_Table
|
|||||||
return $this->_rows;
|
return $this->_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all row heights
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getRowHeights()
|
|
||||||
{
|
|
||||||
return $this->_rowHeights;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get table style
|
* Get table style
|
||||||
*
|
*
|
||||||
|
|||||||
141
Classes/PHPWord/Section/Table/Row.php
Normal file
141
Classes/PHPWord/Section/Table/Row.php
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 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
|
||||||
|
*
|
||||||
|
* @category PHPWord
|
||||||
|
* @package PHPWord
|
||||||
|
* @copyright Copyright (c) 2013 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.7.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHPWord_Section_Table_Row
|
||||||
|
*/
|
||||||
|
class PHPWord_Section_Table_Row
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row height
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_height = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row style
|
||||||
|
*
|
||||||
|
* @var PHPWord_Style_Row
|
||||||
|
*/
|
||||||
|
private $_style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row cells
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_cells = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table holder
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_insideOf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section/Header/Footer count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_pCount;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new table row
|
||||||
|
*
|
||||||
|
* @param string $insideOf
|
||||||
|
* @param int $pCount
|
||||||
|
* @param int $height
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($insideOf, $pCount, $height = null, $style = null)
|
||||||
|
{
|
||||||
|
$this->_insideOf = $insideOf;
|
||||||
|
$this->_pCount = $pCount;
|
||||||
|
$this->_height = $height;
|
||||||
|
$this->_style = new PHPWord_Style_Row();
|
||||||
|
|
||||||
|
if (!is_null($style)) {
|
||||||
|
if (is_array($style)) {
|
||||||
|
|
||||||
|
foreach ($style as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$this->_style->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a cell
|
||||||
|
*
|
||||||
|
* @param int $width
|
||||||
|
* @param mixed $style
|
||||||
|
* @return PHPWord_Section_Table_Cell
|
||||||
|
*/
|
||||||
|
public function addCell($width = null, $style = null)
|
||||||
|
{
|
||||||
|
$cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style);
|
||||||
|
$this->_cells[] = $cell;
|
||||||
|
return $cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all cells
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCells()
|
||||||
|
{
|
||||||
|
return $this->_cells;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get row style
|
||||||
|
*
|
||||||
|
* @return PHPWord_Style_Row
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get row height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHeight()
|
||||||
|
{
|
||||||
|
return $this->_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
85
Classes/PHPWord/Style/Row.php
Normal file
85
Classes/PHPWord/Style/Row.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 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
|
||||||
|
*
|
||||||
|
* @category PHPWord
|
||||||
|
* @package PHPWord
|
||||||
|
* @copyright Copyright (c) 2013 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
* @version 0.7.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHPWord_Style_Row
|
||||||
|
*/
|
||||||
|
class PHPWord_Style_Row
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repeat table row on every new page
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_tblHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table row cannot break across pages
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $_cantSplit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new row style
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->_tblHeader = null;
|
||||||
|
$this->_cantSplit = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*/
|
||||||
|
public function setStyleValue($key, $value)
|
||||||
|
{
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTblHeader($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_tblHeader = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTblHeader()
|
||||||
|
{
|
||||||
|
return $this->_tblHeader ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCantSplit($pValue = null)
|
||||||
|
{
|
||||||
|
$this->_cantSplit = $pValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCantSplit()
|
||||||
|
{
|
||||||
|
return $this->_cantSplit ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -431,22 +431,36 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$_heights = $table->getRowHeights();
|
|
||||||
for ($i = 0; $i < $_cRows; $i++) {
|
for ($i = 0; $i < $_cRows; $i++) {
|
||||||
$row = $_rows[$i];
|
$row = $_rows[$i];
|
||||||
$height = $_heights[$i];
|
$height = $row->getHeight();
|
||||||
|
$rowStyle = $row->getStyle();
|
||||||
|
$tblHeader = $rowStyle->getTblHeader();
|
||||||
|
$cantSplit = $rowStyle->getCantSplit();
|
||||||
|
|
||||||
$objWriter->startElement('w:tr');
|
$objWriter->startElement('w:tr');
|
||||||
|
|
||||||
if (!is_null($height)) {
|
if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) {
|
||||||
$objWriter->startElement('w:trPr');
|
$objWriter->startElement('w:trPr');
|
||||||
$objWriter->startElement('w:trHeight');
|
if (!is_null($height)) {
|
||||||
$objWriter->writeAttribute('w:val', $height);
|
$objWriter->startElement('w:trHeight');
|
||||||
$objWriter->endElement();
|
$objWriter->writeAttribute('w:val', $height);
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
|
if (!is_null($tblHeader)) {
|
||||||
|
$objWriter->startElement('w:tblHeader');
|
||||||
|
$objWriter->writeAttribute('w:val', $tblHeader);
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
|
if (!is_null($cantSplit)) {
|
||||||
|
$objWriter->startElement('w:cantSplit');
|
||||||
|
$objWriter->writeAttribute('w:val', $cantSplit);
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($row as $cell) {
|
foreach ($row->getCells() as $cell) {
|
||||||
$objWriter->startElement('w:tc');
|
$objWriter->startElement('w:tc');
|
||||||
|
|
||||||
$cellStyle = $cell->getStyle();
|
$cellStyle = $cell->getStyle();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user