“必须列出至少一个字段” Google Sheets API移动表错误

时间:2019-08-09 05:24:29

标签: google-api google-sheets-api

基于此答案:

Move a sheet to a particular position using Python & the Google Sheets API

我写了这段代码:

body = {'requests': [
    {'updateSheetProperties': {
        'properties': {
            'sheetId': sheetId,
            'index': 1
        }
    }}
]}
spreadsheet.batch_update(body)

但是我收到此错误:

“无效请求[0] .updateSheetProperties:必须在“字段”中列出至少一个字段。(使用“ *”表示所有字段。)”

如果我添加此内容:

body = {'requests': [
    {'updateSheetProperties': {
        'properties': {
            'sheetId': sheetId,
            'index': 1
        },
        "fields": "*"
    }}
]}

我得到:

“无效请求[0]。updateSheetProperties:工作表名称不能为空。”

我什至尝试使用工作表名称:

"fields": "2019-08-09" 

但是我得到了

“无效请求[0] .updateSheetProperties:无效字段:2019-08-09”

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

  • 您想在Python中使用gspread移动工作表。
    • 您要使用Handler().postDelayed({ mAddressEditText.setText(place.getAddress()); }, 300) 的gspread。
  • 您已经能够使用Sheets API放置和获取电子表格的值。

如果我的理解是正确的,那么该修改如何?

修改后的脚本:

在此修改中,batch_update被修改。

从:
body
至:
body = {'requests': [
    {'updateSheetProperties': {
        'properties': {
            'sheetId': sheetId,
            'index': 1
        }
    }}
]}
  • 根据您的情况,请使用body = {'requests': [ {'updateSheetProperties': { 'properties': { 'sheetId': sheetId, 'index': 1 }, 'fields': 'index', }} ]} index

注意:

  • 要同时移动工作表并重命名工作表名称时,请使用以下请求正文。

    fields

参考:

如果我误解了您的问题,而这不是您想要的方向,我深表歉意。