public function writeStyles(Document_Word_Writer $pPHPWord = null) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } $this->_document = $pPHPWord; // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); $objWriter->startElement('w:styles'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); // Write DocDefaults $this->_writeDocDefaults($objWriter); // Write Style Definitions require_once __DIR__ . '/../../Style.php'; $styles = Document_Word_Writer_Style::getStyles(); if (count($styles) > 0) { foreach ($styles as $styleName => $style) { if ($style instanceof Document_Word_Writer_Style_Font) { $paragraphStyle = $style->getParagraphStyle(); $styleType = $style->getStyleType(); $type = $styleType == 'title' ? 'paragraph' : 'character'; if (!is_null($paragraphStyle)) { $type = 'paragraph'; } $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', $type); if ($styleType == 'title') { $arrStyle = explode('_', $styleName); $styleId = 'Heading' . $arrStyle[1]; $styleName = 'heading ' . $arrStyle[1]; $styleLink = 'Heading' . $arrStyle[1] . 'Char'; $objWriter->writeAttribute('w:styleId', $styleId); $objWriter->startElement('w:link'); $objWriter->writeAttribute('w:val', $styleLink); $objWriter->endElement(); } $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); if (!is_null($paragraphStyle)) { // print_r($paragraphStyle);exit; $this->_writeParagraphStyle($objWriter, $paragraphStyle); } $this->_writeTextStyle($objWriter, $style); $objWriter->endElement(); } elseif ($style instanceof Document_Word_Writer_Style_Paragraph) { $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', 'paragraph'); $objWriter->writeAttribute('w:customStyle', '1'); $objWriter->writeAttribute('w:styleId', $styleName); $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); $this->_writeParagraphStyle($objWriter, $style); $objWriter->endElement(); } elseif ($style instanceof Document_Word_Writer_Style_TableFull) { $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', 'table'); $objWriter->writeAttribute('w:customStyle', '1'); $objWriter->writeAttribute('w:styleId', $styleName); $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); $objWriter->startElement('w:uiPriority'); $objWriter->writeAttribute('w:val', '99'); $objWriter->endElement(); $this->_writeFullTableStyle($objWriter, $style); $objWriter->endElement(); } } } $objWriter->endElement(); // w:styles // Return return $objWriter->getData(); }
/** * Adds a hyperlink style to styles.xml * * @param $styleName string * @param $styles array */ public function addLinkStyle($styleName, $styles) { require_once __DIR__ . '/Writer/Style.php'; Document_Word_Writer_Style::addLinkStyle($styleName, $styles); }
/** * Add a Title Element * * @param string $text * @param int $depth * @return PHPWord_Section_Title */ public function addTitle($text, $depth = 1) { $text = @iconv("UTF-8", "UTF-8//IGNORE", $text); $styles = Document_Word_Writer_Style::getStyles(); if (array_key_exists('Heading_' . $depth, $styles)) { $style = 'Heading' . $depth; } else { $style = null; } require_once __DIR__ . '/Section/Title.php'; $title = new Document_Word_Writer_Section_Title($text, $depth, $style); $data = Document_Word_Writer_TOC::addTitle($text, $depth); $anchor = $data[0]; $bookmarkId = $data[1]; $title->setAnchor($anchor); $title->setBookmarkId($bookmarkId); $this->_elementCollection[] = $title; return $title; }
function handle_p() { if ($this->pass != 2) { return; } $style = $this->parseProps(); if (!empty($style)) { $this->style = array_merge($style, Document_Word_Writer_Style::getStyles()); } else { $this->style = $this->xr->getAttribute('style'); } if ($this->keepSection) { return; } // p must create a text run.. otherwise cells do not work.. $this->section = $this->section->createTextRun($this->style); }