(1) new width property for table; (2) allow table cell width to be null

This commit is contained in:
Ivan Lanin 2014-01-13 23:14:05 +07:00
parent d55db9da83
commit 4d94d5763c
3 changed files with 40 additions and 1 deletions

View File

@ -66,6 +66,13 @@ class PHPWord_Section_Table
*/
private $_pCount;
/**
* Table width
*
* @var int
*/
private $_width = null;
/**
* Create a new table
@ -113,7 +120,7 @@ class PHPWord_Section_Table
* @param mixed $style
* @return PHPWord_Section_Table_Cell
*/
public function addCell($width, $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;
@ -150,4 +157,25 @@ class PHPWord_Section_Table
{
return $this->_style;
}
/**
* Set table width
*
* @var int $width
*/
public function setWidth($width)
{
$this->_width = $width;
}
/**
* Get table width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
}

View File

@ -30,6 +30,10 @@
*/
class PHPWord_Style_Table
{
const WIDTH_TYPE_NIL = 'nil'; // No Width
const WIDTH_TYPE_PERCENT = 'pct'; // Width in Fiftieths of a Percent
const WIDTH_TYPE_POINT = 'dxa'; // Width in Twentieths of a Point
const WIDTH_TYPE_AUTO = 'auto'; // Automatically Determined Width
private $_cellMarginTop;
private $_cellMarginLeft;

View File

@ -412,6 +412,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
if ($_cRows > 0) {
$objWriter->startElement('w:tbl');
$tblStyle = $table->getStyle();
$tblWidth = $table->getWidth();
if ($tblStyle instanceof PHPWord_Style_Table) {
$this->_writeTableStyle($objWriter, $tblStyle);
} else {
@ -420,6 +421,12 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->startElement('w:tblStyle');
$objWriter->writeAttribute('w:val', $tblStyle);
$objWriter->endElement();
if (!is_null($tblWidth)) {
$objWriter->startElement('w:tblW');
$objWriter->writeAttribute('w:w', $tblWidth);
$objWriter->writeAttribute('w:type', 'pct');
$objWriter->endElement();
}
$objWriter->endElement();
}
}