style instanceof \PhpOffice\PhpWord\Style\Table)) { return; } $hasBorders = $this->style->hasBorders(); $hasMargins = $this->style->hasMargins(); if ($hasMargins || $hasBorders) { $this->xmlWriter->startElement('w:tblPr'); if ($hasMargins) { $mbWriter = new MarginBorder($this->xmlWriter); $mbWriter->setSizes($this->style->getCellMargin()); $this->xmlWriter->startElement('w:tblCellMar'); $mbWriter->write(); $this->xmlWriter->endElement(); // w:tblCellMar } if ($hasBorders) { $mbWriter = new MarginBorder($this->xmlWriter); $mbWriter->setSizes($this->style->getBorderSize()); $mbWriter->setColors($this->style->getBorderColor()); $this->xmlWriter->startElement('w:tblBorders'); $mbWriter->write(); $this->xmlWriter->endElement(); // w:tblBorders } $this->xmlWriter->endElement(); // w:tblPr } // Only write background color and first row for full style if ($this->isFullStyle) { // Background color if (!is_null($this->style->getShading())) { $this->xmlWriter->startElement('w:tcPr'); $styleWriter = new Shading($this->xmlWriter, $this->style->getShading()); $styleWriter->write(); $this->xmlWriter->endElement(); } // First Row $firstRow = $this->style->getFirstRow(); if ($firstRow instanceof \PhpOffice\PhpWord\Style\Table) { $this->writeFirstRow($firstRow, 'firstRow'); } } } /** * Set is full style * * @param bool $value */ public function setIsFullStyle($value) { $this->isFullStyle = $value; } /** * 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 if ($style->hasBorders()) { $mbWriter = new MarginBorder($this->xmlWriter); $mbWriter->setSizes($style->getBorderSize()); $mbWriter->setColors($style->getBorderColor()); $this->xmlWriter->startElement('w:tcBorders'); $mbWriter->write(); $this->xmlWriter->endElement(); // w:tcBorders } $this->xmlWriter->endElement(); // w:tcPr $this->xmlWriter->endElement(); // w:tblStylePr } }