88 lines
2.5 KiB
PHP
Raw Normal View History

2014-04-26 11:14:27 +07:00
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
2014-04-26 11:14:27 +07:00
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\Shading;
2014-04-26 11:14:27 +07:00
/**
* Cell style writer
*
* @since 0.10.0
*/
class Cell extends AbstractStyle
{
/**
* Write style
*/
public function write()
{
if (!($this->style instanceof \PhpOffice\PhpWord\Style\Cell)) {
return;
}
$brdSz = $this->style->getBorderSize();
$brdCol = $this->style->getBorderColor();
$hasBorders = false;
for ($i = 0; $i < 4; $i++) {
if (!is_null($brdSz[$i])) {
$hasBorders = true;
break;
}
}
// Border
if ($hasBorders) {
$mbWriter = new MarginBorder($this->xmlWriter);
$mbWriter->setSizes($brdSz);
$mbWriter->setColors($brdCol);
$mbWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR));
2014-04-26 11:14:27 +07:00
$this->xmlWriter->startElement('w:tcBorders');
$mbWriter->write();
$this->xmlWriter->endElement();
}
2014-04-26 11:14:27 +07:00
// Text direction
if (!is_null($this->style->getTextDirection())) {
$this->xmlWriter->startElement('w:textDirection');
$this->xmlWriter->writeAttribute('w:val', $this->style->getTextDirection());
$this->xmlWriter->endElement();
}
2014-04-26 11:14:27 +07:00
// Shading
if (!is_null($this->style->getShading())) {
$styleWriter = new Shading($this->xmlWriter, $this->style->getShading());
$styleWriter->write();
}
2014-04-26 11:14:27 +07:00
// Alignment
if (!is_null($this->style->getVAlign())) {
$this->xmlWriter->startElement('w:vAlign');
$this->xmlWriter->writeAttribute('w:val', $this->style->getVAlign());
$this->xmlWriter->endElement();
2014-04-26 11:14:27 +07:00
}
// Colspan
if (!is_null($this->style->getGridSpan())) {
2014-04-26 11:14:27 +07:00
$this->xmlWriter->startElement('w:gridSpan');
$this->xmlWriter->writeAttribute('w:val', $this->style->getGridSpan());
2014-04-26 11:14:27 +07:00
$this->xmlWriter->endElement();
}
// Row span
if (!is_null($this->style->getVMerge())) {
2014-04-26 11:14:27 +07:00
$this->xmlWriter->startElement('w:vMerge');
$this->xmlWriter->writeAttribute('w:val', $this->style->getVMerge());
2014-04-26 11:14:27 +07:00
$this->xmlWriter->endElement();
}
}
}