No Description

Sample_25_TextBox.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. $section = $phpWord->addSection();
  7. // In section
  8. $textbox = $section->addTextBox(
  9. array(
  10. 'align' => 'center',
  11. 'width' => 400,
  12. 'height' => 150,
  13. 'borderSize' => 1,
  14. 'borderColor' => '#FF0000',
  15. )
  16. );
  17. $textbox->addText(htmlspecialchars('Text box content in section.'));
  18. $textbox->addText(htmlspecialchars('Another line.'));
  19. $cell = $textbox->addTable()->addRow()->addCell();
  20. $cell->addText(htmlspecialchars('Table inside textbox'));
  21. // Inside table
  22. $section->addTextBreak(2);
  23. $cell = $section->addTable()->addRow()->addCell(300);
  24. $textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
  25. $textbox->addText(htmlspecialchars('Textbox inside table'));
  26. // Inside header with textrun
  27. $header = $section->addHeader();
  28. $textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
  29. $textrun = $textbox->addTextRun();
  30. $textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun '));
  31. $textrun->addText(htmlspecialchars('with bold text'), array('bold' => true));
  32. $textrun->addText(htmlspecialchars(', '));
  33. $textrun->addLink('http://www.google.com', htmlspecialchars('link'));
  34. $textrun->addText(htmlspecialchars(', and image '));
  35. $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
  36. $textrun->addText(htmlspecialchars('.'));
  37. // Save file
  38. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  39. if (!CLI) {
  40. include_once 'Sample_Footer.php';
  41. }