Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the gid (tabs) in Google Spreadsheet API v4?

I am trying to use RESTful API to gather the data from a Google spreadsheet spreadsheet.

I read the document at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get but I cannot a way that allows me to specify a specific GID (tabs) of the spreadsheet.

After call the API, I was able to get a value from the first tab of the spreadsheet, but I want to change it to the second page (another GID)

Any help would be appreciated. Thanks.

Edit: Added example:

I have a sample spreadsheet here: https://docs.google.com/spreadsheets/d/1da3e6R08S8OoibbOgshyAQy7m9VRGPOrSGzVIvMSXf4/edit#gid=0

When I want to get the value on A1, I can call the RESTful API:

https://content-sheets.googleapis.com/v4/spreadsheets/1da3e6R08S8OoibbOgshyAQy7m9VRGPOrSGzVIvMSXf4/values/A1?key=API_KEY

And I will get:

{
  "range": "Sheet1!A1",
  "majorDimension": "ROWS",
  "values": [
    [
      "This is on the first tab!"
    ]
  ]
}

But as you see in my spreadsheet, I have to tabs (sheet2), how can I get that value of "This is on the second tab!"?

like image 999
Jamie Phan Avatar asked May 02 '17 08:05

Jamie Phan


People also ask

How do I reference different tabs in Google Sheets?

Get data from other sheets in your spreadsheetType = followed by the sheet name, an exclamation point, and the cell being copied. For example, =Sheet1! A1 or ='Sheet number two'! B4 .

How do I find GID in Google Sheets?

Sheet ID is an identifier of a Sheet in a Google Spreadsheet file. To obtain it, open the file for the desired Sheet, and locate it at the end of the URL after 'gid=' : https://docs.google.com/spreadsheets/d/1EwXZweUNKKGSC6k6_6IkukyRFeNzi7qEIIjOAC9_vGA/edit#gid=ThisIsSheetID .

What is GID in Google Sheets URL?

Google Grid ID (gid) is the sheet ID (tab) used to specify the sheet from which data is being read. The sheetID of the open sheet is the value of the gid parameter at the end of the spreadsheet URL. The gid parameter will be a numerical value.

What does GID mean in Google Sheets?

https://docs.google.com/spreadsheets/d/aBC-123_xYz/edit#gid= sheetId. Cell. An individual field of text or data within a sheet. Cells are arranged in rows and columns, and can be grouped as a range of cells.


1 Answers

To specify a specific GID (tabs) of the spreadsheet. Enter your 'sheet_name' with single quotes. Don't miss to add double quotes for range. Hope it helps

var query = {
        auth: authClient,
        spreadsheetId: 'spreadsheetID', 
        range: "'sheet1'!A1:D3",
    };
like image 198
RAMESHKUMAR Avatar answered Sep 19 '22 03:09

RAMESHKUMAR