/** * Create a new Table Cell * * @param string $insideOf * @param int $pCount * @param int $width * @param mixed $style */ public function __construct($insideOf, $pCount, $width = null, $style = null) { $this->_insideOf = $insideOf; $this->_pCount = $pCount; $this->_width = $width; if (!is_null($style)) { if (is_array($style)) { $this->_style = new PHPWord_Style_Cell(); foreach ($style as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; } $this->_style->setStyleValue($key, $value); } } else { $this->_style = $style; } } }
/** * Create a new Table Cell * * @param string $insideOf * @param int $pCount * @param int $width * @param mixed $style */ public function __construct($insideOf, $pCount, $width = null, $style = null) { require_once __DIR__ . '/../../Style/Cell.php'; $this->_insideOf = $insideOf; $this->_pCount = $pCount; $this->_width = $width; if (!is_null($style)) { if (is_array($style)) { $this->_style = new Document_Word_Writer_Style_Cell(); foreach ($style as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; } $this->_style->setStyleValue($key, $value); } } else { $this->_style = $style; } } }
protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) { $bgColor = $style->getBgColor(); $valign = $style->getVAlign(); $textDir = $style->getTextDirection(); $brdSz = $style->getBorderSize(); $brdCol = $style->getBorderColor(); $bTop = !is_null($brdSz[0]) ? true : false; $bLeft = !is_null($brdSz[1]) ? true : false; $bRight = !is_null($brdSz[2]) ? true : false; $bBottom = !is_null($brdSz[3]) ? true : false; $borders = $bTop || $bLeft || $bRight || $bBottom ? true : false; $styles = !is_null($bgColor) || !is_null($valign) || !is_null($textDir) || $borders ? true : false; if ($styles) { if (!is_null($textDir)) { $objWriter->startElement('w:textDirection'); $objWriter->writeAttribute('w:val', $textDir); $objWriter->endElement(); } if (!is_null($bgColor)) { $objWriter->startElement('w:shd'); $objWriter->writeAttribute('w:val', 'clear'); $objWriter->writeAttribute('w:color', 'auto'); $objWriter->writeAttribute('w:fill', $bgColor); $objWriter->endElement(); } if (!is_null($valign)) { $objWriter->startElement('w:vAlign'); $objWriter->writeAttribute('w:val', $valign); $objWriter->endElement(); } if ($borders) { $_defaultColor = $style->getDefaultBorderColor(); $objWriter->startElement('w:tcBorders'); if ($bTop) { if (is_null($brdCol[0])) { $brdCol[0] = $_defaultColor; } $objWriter->startElement('w:top'); $objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:sz', $brdSz[0]); $objWriter->writeAttribute('w:color', $brdCol[0]); $objWriter->endElement(); } if ($bLeft) { if (is_null($brdCol[1])) { $brdCol[1] = $_defaultColor; } $objWriter->startElement('w:left'); $objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:sz', $brdSz[1]); $objWriter->writeAttribute('w:color', $brdCol[1]); $objWriter->endElement(); } if ($bRight) { if (is_null($brdCol[2])) { $brdCol[2] = $_defaultColor; } $objWriter->startElement('w:right'); $objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:sz', $brdSz[2]); $objWriter->writeAttribute('w:color', $brdCol[2]); $objWriter->endElement(); } if ($bBottom) { if (is_null($brdCol[3])) { $brdCol[3] = $_defaultColor; } $objWriter->startElement('w:bottom'); $objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:sz', $brdSz[3]); $objWriter->writeAttribute('w:color', $brdCol[3]); $objWriter->endElement(); } $objWriter->endElement(); } } $gridSpan = $style->getGridSpan(); if (!is_null($gridSpan)) { $objWriter->startElement('w:gridSpan'); $objWriter->writeAttribute('w:val', $gridSpan); $objWriter->endElement(); } $vMerge = $style->getVMerge(); if (!is_null($vMerge)) { $objWriter->startElement('w:vMerge'); $objWriter->writeAttribute('w:val', $vMerge); $objWriter->endElement(); } }