/** * Create new table style * * @param mixed $tableStyle * @param mixed $firstRowStyle */ public function __construct($tableStyle = null, $firstRowStyle = null) { // Clone first row from table style, but with certain properties disabled if ($firstRowStyle !== null && is_array($firstRowStyle)) { $this->firstRowStyle = clone $this; $this->firstRowStyle->isFirstRow = true; unset($this->firstRowStyle->firstRowStyle); unset($this->firstRowStyle->borderInsideHSize); unset($this->firstRowStyle->borderInsideHColor); unset($this->firstRowStyle->borderInsideVSize); unset($this->firstRowStyle->borderInsideVColor); unset($this->firstRowStyle->cellMarginTop); unset($this->firstRowStyle->cellMarginLeft); unset($this->firstRowStyle->cellMarginRight); unset($this->firstRowStyle->cellMarginBottom); $this->firstRowStyle->setStyleByArray($firstRowStyle); } if ($tableStyle !== null && is_array($tableStyle)) { $this->setStyleByArray($tableStyle); } }
/** * Create new table style * * @param mixed $styleTable * @param mixed $styleFirstRow */ public function __construct($styleTable = null, $styleFirstRow = null) { if (!is_null($styleFirstRow) && is_array($styleFirstRow)) { $this->firstRow = clone $this; unset($this->firstRow->firstRow); unset($this->firstRow->cellMarginBottom); unset($this->firstRow->cellMarginTop); unset($this->firstRow->cellMarginLeft); unset($this->firstRow->cellMarginRight); unset($this->firstRow->borderInsideVColor); unset($this->firstRow->borderInsideVSize); unset($this->firstRow->borderInsideHColor); unset($this->firstRow->borderInsideHSize); foreach ($styleFirstRow as $key => $value) { $this->firstRow->setStyleValue($key, $value); } } if (!is_null($styleTable) && is_array($styleTable)) { foreach ($styleTable as $key => $value) { $this->setStyleValue($key, $value); } } }
/** * Write shading. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style * @return void */ private function writeShading(XMLWriter $xmlWriter, TableStyle $style) { if (null !== $style->getShading()) { $xmlWriter->startElement('w:tcPr'); $styleWriter = new Shading($xmlWriter, $style->getShading()); $styleWriter->write(); $xmlWriter->endElement(); } }
/** * Write row style * * @param string $type */ private function writeFirstRow(\PhpOffice\PhpWord\Style\Table $style, $type) { $this->xmlWriter->startElement('w:tblStylePr'); $this->xmlWriter->writeAttribute('w:type', $type); $this->xmlWriter->startElement('w:tcPr'); if (!is_null($style->getShading())) { $styleWriter = new Shading($this->xmlWriter, $style->getShading()); $styleWriter->write(); } // Borders $brdSz = $style->getBorderSize(); $brdCol = $style->getBorderColor(); $hasBorders = false; for ($i = 0; $i < 6; $i++) { if (!is_null($brdSz[$i])) { $hasBorders = true; } } if ($hasBorders) { $mbWriter = new MarginBorder($this->xmlWriter); $mbWriter->setSizes($brdSz); $mbWriter->setColors($brdCol); $this->xmlWriter->startElement('w:tcBorders'); $mbWriter->write(); $this->xmlWriter->endElement(); // w:tcBorders } $this->xmlWriter->endElement(); // w:tcPr $this->xmlWriter->endElement(); // w:tblStylePr }
/** * Set style values and put it to static style collection * * @param string $styleName * @param Paragraph|Font|Table|Numbering $styleObject * @param array|null $styleValues */ private static function setStyleValues($styleName, $styleObject, $styleValues = null) { if (!array_key_exists($styleName, self::$styles)) { if (!is_null($styleValues) && is_array($styleValues)) { foreach ($styleValues as $key => $value) { $styleObject->setStyleValue($key, $value); } } $styleObject->setStyleName($styleName); $styleObject->setIndex(self::countStyles() + 1); // One based index self::$styles[$styleName] = $styleObject; } }
/** * Set style value for various special value types */ public function testSetStyleValue() { $object = new Table(); $object->setStyleValue('borderSize', 120); $object->setStyleValue('cellMargin', 240); $object->setStyleValue('borderColor', '999999'); $this->assertEquals(array(120, 120, 120, 120, 120, 120), $object->getBorderSize()); $this->assertEquals(array(240, 240, 240, 240), $object->getCellMargin()); $this->assertEquals(array('999999', '999999', '999999', '999999', '999999', '999999'), $object->getBorderColor()); }