如何在页脚中插入 PAGE_NUMBER 和 PAGE_COUNT

How to insert PAGE_NUMBER and PAGE_COUNT in footer

我正在寻找页脚中段落和元素段落的示例。 我试过了,但我只能在页脚中插入文本:

$requests = array (new \Google_Service_Docs_Request(array(
    'insertText' => array(
        'location' => array(
            'segmentId' => $segmentId,
                'index' => 0
            ),
            "text" => 'My Text'
        )
)),

我试过像这样实现新的页脚:

$footers = array(
        new \Google_Service_Docs_Footer(array(
            'footerId' => $segmentId,
            'content' => [
                'paragraph' => [
                    'element' => [
                        'textRun' => [
                            'content' => 'My Text - '
                        ]
                    ]
                ]
            ]
        )),
        new \Google_Service_Docs_Footer(array(
            'footerId' => $segmentId,
            'content' => [
                  'paragraph' => [
                      'element' => [
                          'AutoText' => [
                              'type' => 'PAGE_NUMBER'
                          ]
                      ]
                  ]
            ]
        )),
        new \Google_Service_Docs_Footer(array(
            'footerId' => $segmentId,
            'content' => [
                'paragraph' => [
                    'element' => [
                        'AutoText' => [
                            'type' => 'PAGE_COUNT'
                        ]
                    ]
                ]
            ]
        ))
    );
    $document->setFooters($footers);

我们可以管理页脚的段落吗?

我不认为你可以插入 AutoText through the API. There is no valid request from batchUpdate that can be used for that (text inserted via InsertTextRequest 必须是一个字符串)。因此,PAGE_NUMBERPAGE_COUNT 只能通过 UI 设置:如果您使用 API,则只能检索它们。

我建议您在 this Issue Tracker component 中提交关于此问题的功能请求。

参考:

问题正在进行中https://issuetracker.google.com/issues/149275293 当我有反馈时,我会与您保持联系