Brak opisu

Sample_14_ListItem.php 4.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Begin code
  7. $section = $phpWord->addSection();
  8. // Style definition
  9. $phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000'));
  10. $phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95));
  11. $phpWord->addNumberingStyle(
  12. 'multilevel',
  13. array(
  14. 'type' => 'multilevel',
  15. 'levels' => array(
  16. array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
  17. array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
  18. ),
  19. )
  20. );
  21. $predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
  22. // Lists
  23. $section->addText(htmlspecialchars('Multilevel list.'));
  24. $section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel');
  25. $section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel');
  26. $section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel');
  27. $section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel');
  28. $section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel');
  29. $section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel');
  30. $section->addTextBreak(2);
  31. $section->addText(htmlspecialchars('Basic simple bulleted list.'));
  32. $section->addListItem(htmlspecialchars('List Item 1'));
  33. $section->addListItem(htmlspecialchars('List Item 2'));
  34. $section->addListItem(htmlspecialchars('List Item 3'));
  35. $section->addTextBreak(2);
  36. $section->addText(htmlspecialchars('Continue from multilevel list above.'));
  37. $section->addListItem(htmlspecialchars('List Item IV'), 0, null, 'multilevel');
  38. $section->addListItem(htmlspecialchars('List Item IV.a'), 1, null, 'multilevel');
  39. $section->addTextBreak(2);
  40. $section->addText(htmlspecialchars('Multilevel predefined list.'));
  41. $section->addListItem(htmlspecialchars('List Item 1'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  42. $section->addListItem(htmlspecialchars('List Item 2'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  43. $section->addListItem(htmlspecialchars('List Item 3'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  44. $section->addListItem(htmlspecialchars('List Item 4'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  45. $section->addListItem(htmlspecialchars('List Item 5'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  46. $section->addListItem(htmlspecialchars('List Item 6'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  47. $section->addListItem(htmlspecialchars('List Item 7'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
  48. $section->addTextBreak(2);
  49. $section->addText(htmlspecialchars('List with inline formatting.'));
  50. $listItemRun = $section->addListItemRun();
  51. $listItemRun->addText(htmlspecialchars('List item 1'));
  52. $listItemRun->addText(htmlspecialchars(' in bold'), array('bold' => true));
  53. $listItemRun = $section->addListItemRun();
  54. $listItemRun->addText(htmlspecialchars('List item 2'));
  55. $listItemRun->addText(htmlspecialchars(' in italic'), array('italic' => true));
  56. $listItemRun = $section->addListItemRun();
  57. $listItemRun->addText(htmlspecialchars('List item 3'));
  58. $listItemRun->addText(htmlspecialchars(' underlined'), array('underline' => 'dash'));
  59. $section->addTextBreak(2);
  60. // Numbered heading
  61. $phpWord->addNumberingStyle(
  62. 'headingNumbering',
  63. array('type' => 'multilevel',
  64. 'levels' => array(
  65. array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
  66. array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
  67. array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
  68. ),
  69. )
  70. );
  71. $phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
  72. $phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
  73. $phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
  74. $section->addTitle(htmlspecialchars('Heading 1'), 1);
  75. $section->addTitle(htmlspecialchars('Heading 2'), 2);
  76. $section->addTitle(htmlspecialchars('Heading 3'), 3);
  77. // Save file
  78. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  79. if (!CLI) {
  80. include_once 'Sample_Footer.php';
  81. }