【问题标题】:Setting date format in Google Sheets using API and Python使用 API 和 Python 在 Google 表格中设置日期格式
【发布时间】:2017-08-25 09:26:10
【问题描述】:

我正在尝试在列上设置日期格式,以便日期显示如下:14-Aug-2017。我就是这样做的:

requests = [
    {
        'repeatCell':
        {
            'range':
            {
                'startRowIndex': 1,
                'startColumnIndex': 4,
                'endColumnIndex': 4
            },
            'cell':
            {
                "userEnteredFormat":
                {
                    "numberFormat":
                    {
                        "type": "DATE",
                        "pattern": "dd-mmm-yyyy"
                    }
                }
            },
            'fields': 'userEnteredFormat.numberFormat'
        }
    }
]
body = {"requests": requests}
response = service.spreadsheets().batchUpdate(spreadsheetId=SHEET, body=body).execute()

我希望更新 E 列中除标题单元格之外的所有单元格,因此要更新范围定义。我使用http://wescpy.blogspot.co.uk/2016/09/formatting-cells-in-google-sheets-with.htmlhttps://developers.google.com/sheets/api/samples/formatting 作为这种方法的基础。

但是,单元格不使用该格式显示其内容。它们继续采用“自动”格式,显示我存储的数值(从 1900 年 1 月 1 日开始的天数)或(有时)日期。

将 sheetId 添加到范围定义不会改变结果。

我没有从服务返回错误,响应仅包含电子表格 ID 和空回复结构 [{}]。

我做错了什么?

【问题讨论】:

    标签: google-sheets-api


    【解决方案1】:

    我发现了错误 - endColumnIndex 需要为 5,而不是 4。

    我没有仔细阅读第一篇链接的文章!

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多