我刚开始使用Sheets API,并且正在按照此设置来创建新的工作表:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create
在此代码中,电子表格主体对象为空。为此,我使用了此页面上的示例:https://developers.google.com/sheets/api/samples/writing并将此代码添加到了电子表格主体变量:
{
"range": "Sheet1!A1:D5",
"majorDimension": "ROWS",
"values": [
["Item", "Cost", "Stocked", "Ship Date"],
["Wheel", "$20.50", "4", "3/1/2016"],
["Door", "$15", "2", "3/15/2016"],
["Engine", "$100", "1", "30/20/2016"],
["Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)"]
],
}
但是,当我发布此消息时,出现错误“接收到无效的JSON有效负载。'电子表格'上的未知名称“范围”:找不到字段。”。这里可能出什么问题了?
答案 0 :(得分:1)
您正在使用的请求正文用于spreadsheets.values.update。
作为示例,用于创建电子表格的请求正文如下。在此示例请求正文中,使用了the document中的["Item", "Cost", "Stocked", "Ship Date"], ["Wheel", "$20.50", "4", "3/1/2016"]
。
{
"properties":
{
"title": "sampleSpreadsheet"
},
"sheets":
[
{
"data":
[
{
"startRow": 0,
"startColumn": 0,
"rowData":
[
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "Item"
}
},
{
"userEnteredValue":
{
"stringValue": "Cost"
}
},
{
"userEnteredValue":
{
"stringValue": "Stocked"
}
},
{
"userEnteredValue":
{
"stringValue": "Ship Date"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "Wheel"
}
},
{
"userEnteredValue":
{
"numberValue": 20.5
},
"userEnteredFormat":
{
"numberFormat":
{
"type": "NUMBER",
"pattern": "$##.00"
}
}
},
{
"userEnteredValue":
{
"numberValue": 4
}
},
{
"userEnteredValue":
{
"numberValue": 42372
},
"userEnteredFormat":
{
"numberFormat":
{
"type": "DATE",
"pattern": "d/m/yyyy"
}
}
}
]
}
]
}
]
}
]
}
sampleSpreadsheet
的电子表格。该工作表在“ A1:D2”处的值为["Item", "Cost", "Stocked", "Ship Date"], ["Wheel", "$20.50", "4", "3/1/2016"]
。如果这对您的情况没有帮助,对不起。