103 lines
2.9 KiB
PHP
Raw Normal View History

2014-04-26 11:14:27 +07:00
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
2014-04-26 11:14:27 +07:00
*
* @link https://github.com/PHPOffice/PHPWord
* @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;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
2014-04-26 11:14:27 +07:00
/**
* Cell style writer
*
* @since 0.10.0
*/
class Cell extends AbstractStyle
{
/**
* @var int Cell width
*/
private $width;
2014-04-26 11:14:27 +07:00
/**
* Write style.
*
* @return void
2014-04-26 11:14:27 +07:00
*/
public function write()
{
2014-05-11 11:23:46 +07:00
$style = $this->getStyle();
2014-05-15 14:41:08 +07:00
if (!$style instanceof CellStyle) {
2014-04-26 11:14:27 +07:00
return;
}
2014-05-07 09:47:02 +07:00
$xmlWriter = $this->getXmlWriter();
2014-04-26 11:14:27 +07:00
$xmlWriter->startElement('w:tcPr');
// Width
$xmlWriter->startElement('w:tcW');
$xmlWriter->writeAttribute('w:w', $this->width);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement(); // w:tcW
2014-05-07 09:47:02 +07:00
// Text direction
$textDir = $style->getTextDirection();
$xmlWriter->writeElementIf(!is_null($textDir), 'w:textDirection', 'w:val', $textDir);
// Vertical alignment
$vAlign = $style->getVAlign();
$xmlWriter->writeElementIf(!is_null($vAlign), 'w:vAlign', 'w:val', $vAlign);
2014-04-26 11:14:27 +07:00
// Border
if ($style->hasBorder()) {
2014-05-07 09:47:02 +07:00
$xmlWriter->startElement('w:tcBorders');
2014-04-26 11:14:27 +07:00
2014-05-07 09:47:02 +07:00
$styleWriter = new MarginBorder($xmlWriter);
$styleWriter->setSizes($style->getBorderSize());
$styleWriter->setColors($style->getBorderColor());
$styleWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR));
$styleWriter->write();
2014-04-26 11:14:27 +07:00
2014-05-07 09:47:02 +07:00
$xmlWriter->endElement();
}
2014-04-26 11:14:27 +07:00
// Shading
2014-05-08 19:25:29 +07:00
$shading = $style->getShading();
if (!is_null($shading)) {
$styleWriter = new Shading($xmlWriter, $shading);
$styleWriter->write();
}
2014-04-26 11:14:27 +07:00
2014-05-07 09:47:02 +07:00
// Colspan & rowspan
$gridSpan = $style->getGridSpan();
$vMerge = $style->getVMerge();
$xmlWriter->writeElementIf(!is_null($gridSpan), 'w:gridSpan', 'w:val', $gridSpan);
$xmlWriter->writeElementIf(!is_null($vMerge), 'w:vMerge', 'w:val', $vMerge);
$xmlWriter->endElement(); // w:tcPr
}
/**
* Set width.
*
* @param int $value
* @return void
*/
public function setWidth($value = null)
{
$this->width = $value;
2014-04-26 11:14:27 +07:00
}
}