【问题标题】:PHPWord and ListItemRun, reset numberingPHPWord 和 ListItemRun,重置编号
【发布时间】:2015-12-21 07:35:58
【问题描述】:

我正在使用 PhpWord 库来生成 docx 文件。

在大多数情况下我需要从 HTML 生成这个文件,所以如果我想生成数字列表我需要使用

$section->addListItemRun();

所以如果我在文档中生成两个列表,我期待结果

1.Item 1
2.Item 2
3.Item 3

Some text here

1.Item 1
2.Item 2
3.Item 3

但我得到了

1.Item 1
2.Item 2
3.Item 3

Some text here

4.Item 1
5.Item 2
6.Item 3

有人知道如何重置编号吗?

另一个问题,这个库可以用这个方法添加脚注

$section->addFootnote();

我可以更改脚注的标签吗?

谢谢

【问题讨论】:

    标签: php phpword


    【解决方案1】:

    这是 word 中的行为。不是文件。 但是您可以通过创建唯一列表名称来破解

        $n = 1;
        foreach ($lists as $list) {
            // Hack to reset lists
            $listFormat = $phpWord->addNumberingStyle(
                'multilevel-'.$n,
                array('type' => 'multilevel', 'levels' => array(
                        array('format' => 'decimal', 'text' => '%1.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720)                    
                    )
                )
            );
            $section->addText(htmlspecialchars('Multilevel list.'));
            $section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel-'.$n);
            $section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel-'.$n);
            $section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel-'.$n);
            $section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel-'.$n);
            $section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel-'.$n);
            $section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel-'.$n);
            $section->addTextBreak(2);
            $n++;
        }
    

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      相关资源
      最近更新 更多