Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/PhpWord/Style/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class Cell extends Border
*/
const DEFAULT_BORDER_COLOR = '000000';

/**
* @const string Cell width units http://officeopenxml.com/WPtableCellProperties-Width.php
*/
const WIDTH_AUTO = 'auto'; // Automatically determined width
const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit)
const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip)

/**
* Vertical align (top, center, both, bottom)
*
Expand Down Expand Up @@ -93,6 +100,11 @@ class Cell extends Border
*/
private $shading;

/**
* @var string Width unit
*/
private $unit = self::WIDTH_TWIP;

/**
* Get vertical align.
*
Expand Down Expand Up @@ -236,6 +248,30 @@ public function setShading($value = null)
return $this;
}

/**
* Get width unit
*
* @return string
*/
public function getUnit()
{
return $this->unit;
}

/**
* Set width unit
*
* @param string $value
* @return Cell
*/
public function setUnit($value)
{
$enum = array(self::WIDTH_AUTO, self::WIDTH_PERCENT, self::WIDTH_TWIP);
$this->unit = $this->setEnumVal($value, $enum, $this->unit);

return $this;
}

/**
* Get default border color
*
Expand Down
10 changes: 6 additions & 4 deletions src/PhpWord/Writer/Word2007/Style/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ public function write()
$xmlWriter->startElement('w:tcPr');

// Width
$xmlWriter->startElement('w:tcW');
$xmlWriter->writeAttribute('w:w', $this->width);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement(); // w:tcW
if (!is_null($this->width)) {
$xmlWriter->startElement('w:tcW');
$xmlWriter->writeAttribute('w:w', $this->width);
$xmlWriter->writeAttribute('w:type', $style->getUnit());
$xmlWriter->endElement(); // w:tcW
}

// Text direction
$textDir = $style->getTextDirection();
Expand Down