Google Sheet API追加到特定工作表

Google Sheet API append to a specific sheet

根据API,看来我无法指定要在其中附加数据的工作表。它将所有内容附加在第一张纸中。真的是这样吗?

因为我可以创建一个包含多张纸的文件,但是然后我无法在第二张纸上书写?


解决方案是在糟糕的Google Sheets API文档上的{range}参数中指定工作表标题。

以下是请求表中有关更新sheet2上的值的信息...

URL:

1
PUT https://sheets.googleapis.com/v4/spreadsheets/{someSpreadsheetId}/values/sheet2!A1:D3?valueInputOption=USER_ENTERED

身体:

1
2
3
4
5
6
7
{
 "values": [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
  ]
}

请注意,第二张工作表的标题" sheet2 "在我认为的范围之前:" A1:D3 ",带有感叹号分隔符。
sheet2!A1:D3


如果您只想在一张纸上书写,请遵循《基本书写纸》指南。您可以使用PUT方法在纸上书写:

1
PUT https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5?valueInputOption=USER_ENTERED

并以类似方式指定工作表的名称和单元格范围:

1
2
3
4
5
6
7
8
9
10
11
{
 "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)"]
  ],
}

关于您的spreadsheets.values.append问题,我确定您已经阅读了文档中要说的内容:

Appends values to a spreadsheet. The input range is used to search
for existing data and find a"table" within that range. Values will be
appended to the next row of the table, starting with the first column
of the table.

这仅用于在表的最后一行添加。