/** * Add a Text Element * * @var string $text * @var mixed $styleFont * @return PHPWord_Section_Text */ public function addText($text = null, $styleFont = null) { if (!PHPWord_Shared_String::IsUTF8($text)) { $text = utf8_encode($text); } $text = new PHPWord_Section_Text($text, $styleFont); $this->_elementCollection[] = $text; return $text; }
/** * Add a PreserveText Element * * @param string $text * @param mixed $styleFont * @param mixed $styleParagraph * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if (!PHPWord_Shared_String::IsUTF8($text)) { $text = utf8_encode($text); } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; }
/** * Add a Title Element * * @param string $text * @param int $depth * @return PHPWord_Section_Title */ public function addTitle($text, $depth = 1) { if (!PHPWord_Shared_String::IsUTF8($text)) { $text = utf8_encode($text); } $styles = PHPWord_Style::getStyles(); if (array_key_exists('Heading_' . $depth, $styles)) { $style = 'Heading' . $depth; } else { $style = null; } $title = new PHPWord_Section_Title($text, $depth, $style); $data = PHPWord_TOC::addTitle($text, $depth); $anchor = $data[0]; $bookmarkId = $data[1]; $title->setAnchor($anchor); $title->setBookmarkId($bookmarkId); $this->_elementCollection[] = $title; return $title; }
/** * Set a Template value * * @param mixed $search * @param mixed $replace */ public function setValue($search, $replace) { $pattern = '|\\$\\{([^\\}]+)\\}|U'; preg_match_all($pattern, $this->_documentXML, $matches); foreach ($matches[0] as $value) { $valueCleaned = preg_replace('/<[^>]+>/', '', $value); $valueCleaned = preg_replace('/<\\/[^>]+>/', '', $valueCleaned); $this->_documentXML = str_replace($value, $valueCleaned, $this->_documentXML); } if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { $search = '${' . $search . '}'; } if (!is_array($replace)) { if (!PHPWord_Shared_String::IsUTF8($replace)) { $replace = utf8_encode($replace); } } $this->_documentXML = str_replace($search, $replace, $this->_documentXML); }
/** * Add a PreserveText Element * * @param string $text * @param mixed $styleFont * @param mixed $styleParagraph * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') { if (!PHPWord_Shared_String::IsUTF8($text)) { $text = utf8_encode($text); } $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; } else { trigger_error('addPreserveText only supported in footer/header.'); } }