在 PHP 中使用 Google API 在 Google 文档中添加文本时了解范围

发布于 2025-01-09 14:08:29 字数 1541 浏览 2 评论 0原文

我想在 Google Doc 上添加文本,但与“范围”参数混淆。我想了解在向任何 Google 文档添加文本时“范围”参数的作用。我将始终仅在文档顶部添加文本,因此请指导我哪里做错了。此外,我还将针对某些文本添加复选框。以下是我当前用于添加文本然后添加复选框的代码:

$requests[] = new \Google_Service_Docs_Request(
        array(
            'insertText' => array(
                'text' => 'abcdtrig',
                'location' => array(
                    'index' => 10),
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'createParagraphBullets' => array(
                'range' => array(
                    'startIndex' => 1,
                    'endIndex' => 25
                ),
                'bulletPreset' => 'BULLET_CHECKBOX'
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'deleteParagraphBullets' => array(
                'range' => array(
                    'startIndex' => 1,
                    'endIndex' => 2
                )
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'insertText' => array(
                'text' => '#milk',
                'location' => array(
                    'index' => 1),
            ),
        )
    );


    $batchUpdateRequest = new \Google_Service_Docs_BatchUpdateDocumentRequest(array(
        'requests' => $requests
    ));

我希望它的工作方式是每当我运行此脚本时,它都应该在文档顶部添加文本,并且文档的现有内容将向下移动。

请帮助我理解范围的概念,因为其他事情运行良好,我对此很清楚。只需要理解“范围”的概念即可。

I want to add text on Google Doc but confused with "range" parameter. I want to understand the role of "range" parameter while adding text to any Google Doc. I will be adding text always on top of the doc only, so please guide me where I am doing wrong. Additionally I will be adding checkboxes as well against some text too. Following is the code which I am using currently to add text and then add checkbox:

$requests[] = new \Google_Service_Docs_Request(
        array(
            'insertText' => array(
                'text' => 'abcdtrig',
                'location' => array(
                    'index' => 10),
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'createParagraphBullets' => array(
                'range' => array(
                    'startIndex' => 1,
                    'endIndex' => 25
                ),
                'bulletPreset' => 'BULLET_CHECKBOX'
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'deleteParagraphBullets' => array(
                'range' => array(
                    'startIndex' => 1,
                    'endIndex' => 2
                )
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'insertText' => array(
                'text' => '#milk',
                'location' => array(
                    'index' => 1),
            ),
        )
    );


    $batchUpdateRequest = new \Google_Service_Docs_BatchUpdateDocumentRequest(array(
        'requests' => $requests
    ));

I want it to work in a way that whenever I run this script it should add text on top of the doc and existing content of the doc will shift down.

Please help me to understand the concept of range because other things are working fine and I am clear on that. Just need to understand the "range" concept only.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文