Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Google Docs API v1和Python将内联图像居中_Python_Google Docs Api - Fatal编程技术网

如何使用Google Docs API v1和Python将内联图像居中

如何使用Google Docs API v1和Python将内联图像居中,python,google-docs-api,Python,Google Docs Api,我试图使用GoogleDocsAPI和Python将图像居中,我遵循了文档说明,建议定义一个内联图像。图像显示在生成的文档中,但不在文档的中心。 有没有办法使图像居中? 这是我的密码: requests = [ { 'replaceAllText': { 'containsText': { 'text': '{{ customer.name }}', 'matchCas

我试图使用GoogleDocsAPI和Python将图像居中,我遵循了文档说明,建议定义一个内联图像。图像显示在生成的文档中,但不在文档的中心。 有没有办法使图像居中? 这是我的密码:

        requests = [
    {
        'replaceAllText': {
            'containsText': {
                'text': '{{ customer.name }}',
                'matchCase': 'true'
            },
            'replaceText': context['customer'],
        }},
    {
        'insertInlineImage': {
            'location': {
                'index': 55
            },
            'uri':
                'https://www.gstatic.com/images/branding/product/1x/docs_64dp.png',
            'objectSize': {
                'height': {
                    'magnitude': 50,
                    'unit': 'PT'
                },
                'width': {
                    'magnitude': 50,
                    'unit': 'PT'
                }
            }
        }
    }
]
risk_assessment_customer = drive_service.files().copy(fileId=DOCUMENT_ID, body={}).execute()
result = service.documents().batchUpdate(
    documentId=risk_assessment_customer['id'], body={'requests': requests}).execute()
request = drive_service.files().export_media(fileId=result['documentId'],
                                             mimeType='application/pdf')
谢谢

  • 您希望使用Google Docs API将内联图像插入文档中心
  • 您已经将Google Docs API与用于Python的Google客户端库一起使用过
如果我的理解是正确的,这次修改怎么样?在这次修改中,我修改了您的请求正文

修改点:
  • 为了使图像与中心对齐,使用了
    updateParagraphStyle
修改请求正文: 请按如下方式替换请求正文

requests = [
    {
        'replaceAllText': {
            'containsText': {
                'text': '{{ customer.name }}',
                'matchCase': 'true'
            },
            'replaceText': context['customer'],
        }
    },
    {
        "insertInlineImage": {
            "location": {
                "index": 55
            },
            "uri": "https://www.gstatic.com/images/branding/product/1x/docs_64dp.png",
            "objectSize": {
                "height": {
                    "magnitude": 50,
                    "unit": "PT"
                },
                "width": {
                    "magnitude": 50,
                    "unit": "PT"
                }
            }
        }
    },
    {
        "updateParagraphStyle": {
            "range": {
                "startIndex": 55,
                "endIndex": 56
            },
            "paragraphStyle": {
                "alignment": "CENTER"
            },
            "fields": "alignment"
        }
    }
]
参考:
如果这不是你想要的结果,我道歉。

  • 您希望使用Google Docs API将内联图像插入文档中心
  • 您已经将Google Docs API与用于Python的Google客户端库一起使用过
如果我的理解是正确的,这次修改怎么样?在这次修改中,我修改了您的请求正文

修改点:
  • 为了使图像与中心对齐,使用了
    updateParagraphStyle
修改请求正文: 请按如下方式替换请求正文

requests = [
    {
        'replaceAllText': {
            'containsText': {
                'text': '{{ customer.name }}',
                'matchCase': 'true'
            },
            'replaceText': context['customer'],
        }
    },
    {
        "insertInlineImage": {
            "location": {
                "index": 55
            },
            "uri": "https://www.gstatic.com/images/branding/product/1x/docs_64dp.png",
            "objectSize": {
                "height": {
                    "magnitude": 50,
                    "unit": "PT"
                },
                "width": {
                    "magnitude": 50,
                    "unit": "PT"
                }
            }
        }
    },
    {
        "updateParagraphStyle": {
            "range": {
                "startIndex": 55,
                "endIndex": 56
            },
            "paragraphStyle": {
                "alignment": "CENTER"
            },
            "fields": "alignment"
        }
    }
]
参考:

如果这不是您想要的结果,我很抱歉。

我的回答是否显示了您想要的结果?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。如果你对我的回答还有疑问,我道歉。那时候,我可以问一下你目前的情况吗?我想研究解决你的问题。谢谢你的回复。我很高兴你的问题解决了。也谢谢你。我的回答告诉你结果了吗?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。如果你对我的回答还有疑问,我道歉。那时候,我可以问一下你目前的情况吗?我想研究解决你的问题。谢谢你的回复。我很高兴你的问题解决了。也谢谢你。