PHP Word : Ordered Listings

$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
$listItemRun = $section->addListItemRun([$depth], [$listStyle], [$paragraphStyle]);

Basic Usage
addListItem is used for creating lists that only contain plain text. addListItemRun is used for creating complex list items that contains texts with different style (some bold, other italics, etc) or other elements, e.g. images or links.

<?php
//https://phpword.readthedocs.io/en/latest/elements.html#lists
//https://github.com/PHPOffice/PHPWord/issues/1529
require_once 'vendor/autoload.php';
$generatedDocsFolder = "docs/generated/";
$generatedDocName = "orderedList".date('d-m-Y_his').".docx";
$generatedDocPath = $generatedDocsFolder.$generatedDocName;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
/* 
Basic Usage
addListItem is used for creating lists that only contain plain text. addListItemRun is used for creating complex list items that contains texts with different style (some bold, other italics, etc) or other elements, e.g. images or links. 

$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
$listItemRun = $section->addListItemRun([$depth], [$listStyle], [$paragraphStyle]);
 */
$phpWord->addNumberingStyle(
    'multilevel',
    array(
        'type' => 'multilevel',
        'levels' => array(
            array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
            array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
        )
    )
);
$section->addListItem('List Item I', 0, null, 'multilevel');
$section->addListItem('List Item I.a', 1, null, 'multilevel');
$section->addListItem('List Item I.b', 1, null, 'multilevel');
$section->addListItem('List Item II', 0, null, 'multilevel');









$fontStyleName = new \PhpOffice\PhpWord\Style\Font();
$fontStyleName->setBold(true);
$fontStyleName->setName('bookman');
$fontStyleName->setSize(14);
$fontStyleName->setColor(\PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW);//https://stackoverflow.com/questions/40411066/with-phpword-can-you-change-the-true-microsoft-word-text-highlight-color-value

$predefinedMultilevelStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
$paragraphStyleName = 'P-Style';
$phpWord->addParagraphStyle($paragraphStyleName, array('spaceBefore' => 400, 'alignment' => 'end'));

$section->addText('Multilevel predefined list. Test');
$section->addListItem('List Item 1', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addListItem('List Item 2', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addListItem('List Item 3', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addListItem('List Item 4', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addListItem('List Item 5', 2, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addListItem('List Item 6', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addListItem('List Item 7', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName);
$section->addTextBreak(2);

$section->addText('List with inline formatting. Test');
$listItemRun = $section->addListItemRun(0, $predefinedMultilevelStyle, $paragraphStyleName);
$listItemRun->addText('List item 1');
$listItemRun->addText(' in bold', $fontStyleName/* array('bold' => true) */);
$listItemRun = $section->addListItemRun(1, $predefinedMultilevelStyle, $paragraphStyleName);
$listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic' => true));
$footnote = $listItemRun->addFootnote();
$footnote->addText('this is a footnote on a list item');
$listItemRun = $section->addListItemRun(2, $predefinedMultilevelStyle, $paragraphStyleName);
$listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline' => 'dash'));
$section->addTextBreak(2);

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($generatedDocPath);
?>