setPhpWord($phpWord); $this->parts = array('Header', 'Document'); foreach ($this->parts as $partName) { $partClass = get_class($this) . '\\Part\\' . $partName; if (class_exists($partClass)) { /** @var \PhpOffice\PhpWord\Writer\RTF\Part\AbstractPart $part Type hint */ $part = new $partClass(); $part->setParentWriter($this); $this->writerParts[strtolower($partName)] = $part; } } } /** * Save PhpWord to file * * @param string $filename * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) { $content = ''; $filename = $this->getTempFile($filename); $hFile = fopen($filename, 'w'); if ($hFile !== false) { $content .= '{'; $content .= '\rtf1' . PHP_EOL; $content .= $this->getWriterPart('Header')->write(); $content .= $this->getWriterPart('Document')->write(); $content .= '}'; fwrite($hFile, $content); fclose($hFile); } else { throw new Exception("Can't open file"); } $this->cleanupTempFile(); } /** * Get font table */ public function getFontTable() { return $this->getWriterPart('Header')->getFontTable(); } /** * Get color table */ public function getColorTable() { return $this->getWriterPart('Header')->getColorTable(); } /** * Get last paragraph style */ public function getLastParagraphStyle() { return $this->lastParagraphStyle; } /** * Set last paragraph style * * @param mixed $value */ public function setLastParagraphStyle($value = '') { $this->lastParagraphStyle = $value; } }