Brak opisu

Sample_04_Textrun.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. include_once 'Sample_Header.php';
  3. // New Word Document
  4. echo date('H:i:s'), ' Create new PhpWord object', EOL;
  5. $phpWord = new \PhpOffice\PhpWord\PhpWord();
  6. // Ads styles
  7. $phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
  8. $phpWord->addFontStyle('BoldText', array('bold' => true));
  9. $phpWord->addFontStyle('ColoredText', array('color' => 'FF8080', 'bgColor' => 'FFFFCC'));
  10. $phpWord->addLinkStyle(
  11. 'NLink',
  12. array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
  13. );
  14. // New portrait section
  15. $section = $phpWord->addSection();
  16. // Add text run
  17. $textrun = $section->addTextRun('pStyle');
  18. $textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.'));
  19. $textrun->addText(htmlspecialchars(' No break is placed after adding an element.'), 'BoldText');
  20. $textrun->addText(htmlspecialchars(' Both '));
  21. $textrun->addText(htmlspecialchars('superscript'), array('superScript' => true));
  22. $textrun->addText(htmlspecialchars(' and '));
  23. $textrun->addText(htmlspecialchars('subscript'), array('subScript' => true));
  24. $textrun->addText(htmlspecialchars(' are also available.'));
  25. $textrun->addText(
  26. htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.'),
  27. 'ColoredText'
  28. );
  29. $textrun->addText(htmlspecialchars(' Sample Link: '));
  30. $textrun->addLink('http://www.google.com', null, 'NLink');
  31. $textrun->addText(htmlspecialchars(' Sample Image: '));
  32. $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
  33. $textrun->addText(htmlspecialchars(' Sample Object: '));
  34. $textrun->addObject('resources/_sheet.xls');
  35. $textrun->addText(htmlspecialchars(' Here is some more text. '));
  36. // Save file
  37. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  38. if (!CLI) {
  39. include_once 'Sample_Footer.php';
  40. }