Search code examples
phplaravelphpword

Repeat ListItem Numbering in PHPWORD


Is there a way to repeat the ListItem numbering (lettering)?

PHPWORD package

Currently, the output is:

1. One
2. Two
   A. Alpha
   B. Beta
3. Three
   A. Charlie

I want to output this:

1. One
2. Two
   A. Alpha
   B. Beta
2. Three
   A. Charlie

Solution

  • $multilevelList1 = 'multilevel list 1'; // Normal numbering style
    $multilevelList2 = 'multilevel list 2'; // Same style as previous one, but level 0 starts     at 2 instead of 1
    
    $phpWord->addNumberingStyle(
        $multilevelList1,
        array(
            'type'   => 'multilevel',
            'levels' => array(
                array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360, 
                      'start' => 1),
                array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' =>     360, 'tabPos' => 720),
            ),
        )
    );
    
    $phpWord->addNumberingStyle(
        $multilevelList2,
        array(
            'type'   => 'multilevel',
            'levels' => array(
                array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360,
                      'start' => 2),
                array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' =>     360, 'tabPos' => 720),
            ),
        )
    );
    
    
    // New section
    $section = $phpWord->addSection();
    
    // Lists
    $section->addListItem('One',     0, null, $multilevelList1);
    $section->addListItem('Two',     0, null, $multilevelList1);
    $section->addListItem('Alpha',   1, null, $multilevelList1);
    $section->addListItem('Beta',    1, null, $multilevelList1);
    $section->addListItem('Three',   0, null, $multilevelList2);
    $section->addListItem('Charlie', 1, null, $multilevelList2);