/** * Get automatic styles. * * @param \PhpOffice\PhpWord\PhpWord $phpWord * @return void */ private function getAutoStyles(PhpWord $phpWord) { $sections = $phpWord->getSections(); $paragraphStyleCount = 0; $fontStyleCount = 0; foreach ($sections as $section) { $style = $section->getStyle(); $style->setStyleName("Section{$section->getSectionId()}"); $this->autoStyles['Section'][] = $style; $this->getContainerStyle($section, $paragraphStyleCount, $fontStyleCount); } }
/** * Test create/get section */ public function testCreateGetSections() { $phpWord = new PhpWord(); $phpWord->addSection(); $this->assertCount(1, $phpWord->getSections()); }
/** * Set automatic styles */ private function getAutomaticStyles(PhpWord $phpWord) { $sections = $phpWord->getSections(); $sectionCount = count($sections); if ($sectionCount > 0) { $paragraphStyleCount = 0; $fontStyleCount = 0; foreach ($sections as $section) { $elements = $section->getElements(); foreach ($elements as $element) { if ($element instanceof Text) { $fontStyle = $element->getFontStyle(); $paragraphStyle = $element->getParagraphStyle(); // Font if ($fontStyle instanceof Font) { $fontStyleCount++; $arrStyle = array('color' => $fontStyle->getColor(), 'name' => $fontStyle->getName()); $phpWord->addFontStyle('T' . $fontStyleCount, $arrStyle); $element->setFontStyle('T' . $fontStyleCount); // Paragraph } elseif ($paragraphStyle instanceof Paragraph) { $paragraphStyleCount++; $phpWord->addParagraphStyle('P' . $paragraphStyleCount, array()); $element->setParagraphStyle('P' . $paragraphStyleCount); } } } } } }
/** * Test create/get section */ public function testCreateGetSections() { $phpWord = new PhpWord(); $this->assertEquals(new Section(1), $phpWord->addSection()); $phpWord->addSection(); $this->assertEquals(2, count($phpWord->getSections())); }