如何在Google Sheets API中使用工作表ID? [英] How to use sheet ID in Google Sheets API?
问题描述
Google表格文档可以包含一些表格.首先是默认值和"0".通常,对于任何工作表,都有这样的地址:
Google Sheets document can contain some sheets. First is default and '0'. Generally for any sheet there is address like this:
https://docs.google.com/电子表格/d/(spreadsheetId)/edit#gid =(sheetId)
同时具有spreadsheetId
和sheetId
.
但是在 API文档中,没有提到如何使用sheetId
.我只能阅读和编辑给定spreadsheetId
的默认工作表.
But in API documentation there is no mention of how to use sheetId
. I can only read and edit default sheet for given spreadsheetId
.
如果在示例链接中提供的代码的request
中,我添加了sheetId
属性,则出现错误:
If in request
from code presented in exemplary link I added sheetId
property I got error:
{
message: 'Invalid JSON payload received. Unknown name "sheetId": Cannot bind query parameter. Field \'sheetId\' could not be found in request message.',
domain: 'global',
reason: 'badRequest'
}
如何获得除Google Sheets API中默认以外的其他工作表的访问权限,以及如何读取或更新其中的字段?
How to get access to other sheets than default in Google Sheets API and read or update fields in them?
推荐答案
如此处,range
参数可以包含工作表名称,例如
As written here, range
parameter can include sheet names like,
Sheet1!A1
如果必须使用工作表ID代替工作表名称,则可以使用任何使用dataFilter
的替代端点,例如spreadsheets.values.batchUpdateByDataFilter
而不是spreadsheets.values.batchUpdate
.然后,您可以在data.dataFilter.gridRange.sheetId
的请求正文中使用sheetId.
If you must use a sheet id instead of sheet name, You can use any of the alternate end points which uses dataFilter
, like spreadsheets.values.batchUpdateByDataFilter
instead of spreadsheets.values.batchUpdate
. You can then use sheetId in request body at data.dataFilter.gridRange.sheetId
.
但是,开发人员元数据是永久关联对象的首选方法(表格/范围/列)中的变量,希望在此类对象上进行用户修改.
However, developer metadata is the preferred method of permanently associating objects(sheets/ranges/columns) to variables, where user modifications are expected on such objects.
这篇关于如何在Google Sheets API中使用工作表ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!