PHPWord : Ordered list with TemplateProcessor

There are 3 ways to do it

Each methods has its own Pros and Cons

  1. Crass way , Subclassing container class and using templateProcessor->setComplexBlock
    templateProcessor->setComplexBlock will give Error, Uncaught Error: Class 'PhpOffice\PhpWord\Writer\Word2007\Element\Section' not found. That is why container subclass is used
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
class Section extends Container{}

and then

$phpWord = new \PhpOffice\PhpWord\PhpWord();//$this->templateProcessor->makeTable();//new \PhpOffice\PhpWord\PhpWord();
        $section = $phpWord->addSection();        
        $fontStyle = array('size' => 14, 'name' => 'Bookman Old Style'); 
        //$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
        $section->addListItem('List item 1',0,$fontStyle,$fontStyle,$fontStyle);
        $section->addListItem('List item 2',0,$fontStyle,$fontStyle,$fontStyle);
        foreach ($phpWord->getSections() as $section) {// cue from https://stackoverflow.com/questions/52621939/how-to-create-a-word-document-with-all-the-content-of-several-others-with-phpwor
            //$phpWord->addExistingSection($section);            $this->templateProcessor->setComplexBlock ('VAR_4_SECTION', $section);// cue from https://phpword.readthedocs.io/en/latest/templates-processing.html#setcomplexblock
            }
- Pros : Simplest method
- Cons: Modification to core feature, Font of bullet is different
  1. templateProcessor->cloneBlock & templateProcessor->removeBlock Methods
    • Pros : Syncs with intention of PHPword
    • Cons : Issues with PHP 7.2(click) , so need to edit core code PhpOffice\PhpWord\TemplateProcessor
  2. Bringing the effect with 2 column Tables.
    There are 2 ways to do it.

    1. Extracting xml (Click to see code)
    2. TemplateProcessor->setComplexBlock(Click to see code)

    Prose and Cons:

    • Pros: No need to alter core code
    • Cons: More work needed, Not real ordered list.