Textrun.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. require_once '../PHPWord.php';
  3. // New Word Document
  4. $PHPWord = new PHPWord();
  5. // New portrait section
  6. $section = $PHPWord->createSection();
  7. // Add style definitions
  8. $PHPWord->addParagraphStyle('pStyle', array('spacing'=>100));
  9. $PHPWord->addFontStyle('BoldText', array('bold'=>true));
  10. $PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
  11. $PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
  12. // Add text elements
  13. $textrun = $section->createTextRun('pStyle');
  14. $textrun->addText('Each textrun can contain native text or link elements.');
  15. $textrun->addText(' No break is placed after adding an element.', 'BoldText');
  16. $textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText');
  17. $textrun->addText(' The best search engine: ');
  18. $textrun->addLink('http://www.google.com', null, 'NLink');
  19. $textrun->addText('. Also not bad: ');
  20. $textrun->addLink('http://www.bing.com', null, 'NLink');
  21. // Save File
  22. $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
  23. $objWriter->save('Textrun.docx');
  24. ?>