2014-04-26 11:14:27 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @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
|
2014-04-26 11:14:27 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
|
|
|
|
|
2014-05-02 13:39:56 +07:00
|
|
|
use PhpOffice\PhpWord\Style\Cell as CellStyle;
|
2014-05-02 09:45:16 +07:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:39:56 +07:00
|
|
|
// 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
|
|
|
|
2014-05-02 13:39:56 +07:00
|
|
|
$this->xmlWriter->startElement('w:tcBorders');
|
|
|
|
|
$mbWriter->write();
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
2014-04-26 11:14:27 +07:00
|
|
|
|
2014-05-02 13:39:56 +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
|
|
|
|
2014-05-02 13:39:56 +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
|
|
|
|
2014-05-02 13:39:56 +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
|
|
|
}
|
2014-05-02 13:39:56 +07:00
|
|
|
|
|
|
|
|
// Colspan
|
|
|
|
|
if (!is_null($this->style->getGridSpan())) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->startElement('w:gridSpan');
|
2014-05-02 13:39:56 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style->getGridSpan());
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:39:56 +07:00
|
|
|
// Row span
|
|
|
|
|
if (!is_null($this->style->getVMerge())) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->startElement('w:vMerge');
|
2014-05-02 13:39:56 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:val', $this->style->getVMerge());
|
2014-04-26 11:14:27 +07:00
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|