问题
I'm using the Google Spreadsheets API and I'm curious as to whether or not the default first sheet, at the time of creating any new sheet, always has an ID of 0. I tried to research about this, but could not find any documentation regarding this.
Should I assume it will always be 0, or should I get it every time just to be on the safe side, in case they change it?
回答1:
How about this answer?
Situation 1:
When new Spreadsheet is created without the parameter for sheetId
, the sheet, which is existing as the 1st index, has the sheet id of 0
(gid=0
) as the default value. In the current stage, this is the specification. For example, when the following request body is used to create new Spreadsheet, new Spreadsheet which has a sheet of "Sheet1" is created. And the sheet ID of "Sheet1" is 0
.
Request body:
{
"properties": {
"title": "SampleSpreadsheet"
}
}
Endpoint:
POST https://sheets.googleapis.com/v4/spreadsheets
Situation 2:
When new Spreadsheet is created with the parameter for sheetId
, the sheet ID can be given using the parameters. For example, when the following request body is used to create new Spreadsheet, new Spreadsheet which has a sheet of "Sheet1" is created. And the sheet ID of "Sheet1" is 123
.
Request body:
{
"sheets": [
{
"properties": {
"sheetId": 123
}
}
],
"properties": {
"title": "SampleSpreadsheet"
}
}
Endpoint:
POST https://sheets.googleapis.com/v4/spreadsheets
Result:
Should I assume it will always be 0, or should I get it every time just to be on the safe side, in case they change it?
From above situations, the answer for your above question is as follows.
- When new Spreadsheet is created without using the property of
sheetId
for each sheet, the 1st sheet has the sheet ID of0
. - When new Spreadsheet is created with using the property of
sheetId
for each sheet, the 1st sheet can have also the sheet ID except for0
.
Reference:
- Method: spreadsheets.create
If I misunderstood your question and this was not the direction you want, I apologize.
来源:https://stackoverflow.com/questions/56631254/are-google-spreadsheets-first-sheets-always-given-an-id-of-0