示例#1
1
 /**
  * Write footnotes
  */
 public function testWriteNumbering()
 {
     $xmlFile = 'word/numbering.xml';
     $phpWord = new PhpWord();
     $phpWord->addNumberingStyle('numStyle', array('type' => 'multilevel', 'levels' => array(array('start' => 1, 'format' => 'decimal', 'restart' => 1, 'suffix' => 'space', 'text' => '%1.', 'alignment' => Jc::START, 'left' => 360, 'hanging' => 360, 'tabPos' => 360, 'font' => 'Arial', 'hint' => 'default'))));
     $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
     $this->assertTrue($doc->elementExists('/w:numbering/w:abstractNum', $xmlFile));
 }
 /**
  * Test write styles
  */
 public function testWriteStyles()
 {
     $phpWord = new PhpWord();
     $pStyle = array('alignment' => Jc::BOTH);
     $pBase = array('basedOn' => 'Normal');
     $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal');
     $rStyle = array('size' => 20);
     $tStyle = array('bgColor' => 'FF0000', 'cellMargin' => 120, 'borderSize' => 120);
     $firstRowStyle = array('bgColor' => '0000FF', 'borderSize' => 120, 'borderColor' => '00FF00');
     $phpWord->setDefaultParagraphStyle($pStyle);
     $phpWord->addParagraphStyle('Base Style', $pBase);
     $phpWord->addParagraphStyle('New Style', $pNew);
     $phpWord->addFontStyle('New Style', $rStyle, $pStyle);
     $phpWord->addTableStyle('Table Style', $tStyle, $firstRowStyle);
     $phpWord->addTitleStyle(1, $rStyle, $pStyle);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/styles.xml';
     // Normal style generated?
     $path = '/w:styles/w:style[@w:styleId="Normal"]/w:name';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Normal', $element->getAttribute('w:val'));
     // Parent style referenced?
     $path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Base Style', $element->getAttribute('w:val'));
     // Next paragraph style correct?
     $path = '/w:styles/w:style[@w:styleId="New Style"]/w:next';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Normal', $element->getAttribute('w:val'));
 }
 /**
  * Test compatibility
  */
 public function testCompatibility()
 {
     $phpWord = new PhpWord();
     $phpWord->getCompatibility()->setOoxmlVersion(15);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/settings.xml';
     $path = '/w:settings/w:compat/w:compatSetting';
     $this->assertTrue($doc->elementExists($path, $file));
 }
示例#4
0
 /**
  * Test write styles
  */
 public function testFontRTL()
 {
     $phpWord = new \PhpOffice\PhpWord\PhpWord();
     $section = $phpWord->addSection();
     $textrun = $section->addTextRun();
     $textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true));
     $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
     $file = 'word/document.xml';
     $path = '/w:document/w:body/w:p/w:r/w:rPr/w:rtl';
     $this->assertTrue($doc->elementExists($path, $file));
 }
 public function testWriteFootnotes()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('pStyle', array('alignment' => Jc::START));
     $section = $phpWord->addSection();
     $section->addText('Text');
     $footnote1 = $section->addFootnote('pStyle');
     $footnote1->addText('Footnote');
     $footnote1->addTextBreak();
     $footnote1->addLink('https://github.com/PHPOffice/PHPWord');
     $footnote2 = $section->addEndnote(array('alignment' => Jc::START));
     $footnote2->addText('Endnote');
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
     $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference'));
 }
示例#6
0
 /**
  * Check content types
  */
 public function testCheckContentTypes()
 {
     $images = array('mars_noext_jpg' => '1.jpg', 'mars.jpg' => '2.jpg', 'mario.gif' => '3.gif', 'firefox.png' => '4.png', 'duke_nukem.bmp' => '5.bmp', 'angela_merkel.tif' => '6.tif');
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     foreach ($images as $source => $target) {
         $section->addImage(__DIR__ . "/../_files/images/{$source}");
     }
     $doc = TestHelperDOCX::getDocument($phpWord);
     $mediaPath = $doc->getPath() . '/word/media';
     foreach ($images as $source => $target) {
         $this->assertFileEquals(__DIR__ . "/../_files/images/{$source}", $mediaPath . "/section_image{$target}");
     }
 }
示例#7
0
 /**
  * Line height
  */
 public function testLineHeight()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     // Test style array
     $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array(), array('line-height' => 2.0));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
     $lineHeight = $element->getAttribute('w:line');
     $lineRule = $element->getAttribute('w:lineRule');
     $this->assertEquals(480, $lineHeight);
     $this->assertEquals('auto', $lineRule);
     // Test setter
     $text->getParagraphStyle()->setLineHeight(3.0);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
     $lineHeight = $element->getAttribute('w:line');
     $lineRule = $element->getAttribute('w:lineRule');
     $this->assertEquals(720, $lineHeight);
     $this->assertEquals('auto', $lineRule);
 }
示例#8
0
 /**
  * Test SDT elements
  */
 public function testSDTElements()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addSDT('comboBox');
     $section->addSDT('dropDownList');
     $section->addSDT('date');
     $doc = TestHelperDOCX::getDocument($phpWord);
     $path = '/w:document/w:body/w:p/w:sdt/w:sdtPr';
     $this->assertTrue($doc->elementExists($path . '/w:comboBox'));
     $this->assertTrue($doc->elementExists($path . '/w:dropDownList'));
     $this->assertTrue($doc->elementExists($path . '/w:date'));
 }
 /**
  * Test write gutter and line numbering
  */
 public function testWriteGutterAndLineNumbering()
 {
     $pageMarginPath = '/w:document/w:body/w:sectPr/w:pgMar';
     $lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType';
     $phpWord = new PhpWord();
     $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array()));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter'));
     $this->assertTrue($doc->elementExists($lineNumberingPath));
 }
示例#10
0
 /**
  * Test no paragraph style
  */
 public function testWriteNoStyle()
 {
     $phpWord = new PhpWord();
     $phpWord->addFontStyle('Font', array('size' => 11));
     $doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
     $element = '/office:document-content/office:automatic-styles/style:style';
     $this->assertTrue($doc->elementExists($element, 'content.xml'));
 }