首页 > 解决方案 > 在 PHPWORD 中重复 ListItem 编号

问题描述

有没有办法重复 ListItem 编号(字母)?

PHPWORD 包

目前,输出为:

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

我想输出这个:

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

标签: phplaravelphpword

解决方案


$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);

推荐阅读