How to get single sheet from multisheet workbook in Google Sheets - google-sheets

So I have shared a google workbook and I have created a key and so I can retrieve the structure of the workbook with the following link
Google Sheets - Copy of Guardian University Guide 2018
and in the results I can see the sheets in an array, so first element in an array has sheetId of 1544561606 so I presume somehow I can form a second url with this sheetId as well as original spreadsheet id and get the contents of the this sheet but the documentation is sparse IMHO. THen I can do the same for all the other sheets. I just can't find the correct url format. Please help.
This is version 4.0 of Google Sheets API.

From your endpoint, the sheet name of the sheet ID 1544561606 is "Institutional". You can retrieve the sheet data using this sheet name. The endpoint is as follows.
https://sheets.googleapis.com/v4/spreadsheets/1nDSd38lIQj_aTWDRPJ-aPybR0NwFdQ8GLSDJM0-QaR4/values/Institutional?key=AIzaSyBUHA34c7FmNLut1V7Pe3lIJTk3pX39J6E
Reference :
spreadsheets.values.get
If I misunderstand your question, I'm sorry.

Related

Converting Google Form Responses to Google Sheets as a Viewer

Is there a way that I am able to convert a list of Google Form Responses to Google Sheets as a viewer? I have permission to view previous responses, but I am not the owner of the forms.
if you have View access to the spreadsheet you can create a new spreadsheet:
sheets.new
and enter this into A1 cell:
=IMPORTRANGE("URL"; "A:Z")
where URL is the address of the spreadsheet you have View rights and A:Z is the range you want to import. you can even specify the sheet name like: "Sheet1!A:Z" or "Form Responses1!A:Z"

How to insert an embedded sheet via Google Docs API?

I want to insert an embedded Google Sheets table into a Google Doc via the Google Doc API. I had hoped that I could do this via an EmbeddedObject. The definition of EmbeddedObject includes a field for LinkedContentReference, but despite the generic name, a LinkedContentReference object seems to refer only to a Sheets chart.
Is there a way to embed a Sheets table in a Google Doc via API?
I did notice that Google Sheets offers a Table Chart as a chart type. This may be an effective workaround.
You need to insert the sheet table as an inline image
An InlineObject contains an EmbeddedObject such as an image.
Now, when you publish a Google Sheets, you have the option to publish it as pdf, but not image. This mean that you would need to perform an additional step of converting the pdf into a supported image format.
Alternatively you can obtain (and save on your Drive) the Sheet as a thumbNail by performing a Files: get request on the Sheet and setting fields to thumbnailLink. Mind that the thumbNail contians the whole sheet view - not only the data range.
Important:
When performing a documents.batchUpdate request InsertInlineImageRequest, you need to specify the uri in the format
https://docs.google.com/uc?export=view&id=PASTE_HERE_YOUR_ID

Specify target worksheet in structured query of Google Sheets data

I am trying to query data from one of my google spreadsheets, and I have read the docs here.
My spreadsheet has two tabs/sheets. I can query data from the first sheet, but I can't figure out how to query data from the second sheet.
My query url looks like this:
https://docs.google.com/spreadsheets/d/[SpreadSheetId]/gviz/tq?tq=[query]
If I open the sheet in a browser I can see the sheet Id in the browser url:
https://docs.google.com/spreadsheets/d/[SpreadSheetId]/edit#gid=[SheetId]
Is there any way to specify this sheetId in the query url? I have tried adding various versions of /#gid=[sheetId] to my query url but it returns the full html of the page, not the json I expect.
The answer is:
https://docs.google.com/spreadsheets/d/[spreadSheetId]/gviz/tq?gid=[sheetId]&tq=[query]
Credits to tehhowch for pointing me in the right direction!

How can I get single sheet from a spreadsheet collection from Google Sheets with Google Sheets API v4?

I'm trying to build a webapp based on Google Sheets. I'm a little bit confused with the API. I have a spreadsheet which is shared with me by Drive and contains 2 sheets. I can get the first sheet with
GET /v4/spreadsheets/{spreadsheetId}
Returns the spreadsheet at the given ID.
endpoint. But I couldn't figure out how to get the second sheet. Is there a way I can get spesific sheet from a spreadsheet?
The problem in here is when you are using ranges parameter you have to specify the sheet title with A1 notation syntax as described in this document: https://developers.google.com/sheets/guides/concepts#sheet_id
I was using the ranges parameter and using the A1 notation correctly but I wasn't specifying the sheet title. In that scenario the default sheet is the first one. If you want the get another sheet other than the first one you have to specify the title, like this:
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}?ranges=sheetTitle!A3:F20

data from specific google spreadsheet tabs

I know how to query data from google spreadsheet with the general share link, but I want to pull data from specific tabs in that shared workbook. How do I do this?
It is not clear from your question how you are querying a spreadsheet (there are several ways to do it).
If you are using spreadsheet data source url (e.g: https://docs.google.com/spreadsheets/d/{ss_key}/gviz/tq?tq=...), then you can add gid or sheet url parameters to specify which sheet in the spreadsheet to query by its id or name:
https://docs.google.com/spreadsheets/d/{ss_key}/gviz/tq?gid=0&tq=...
https://docs.google.com/spreadsheets/d/{ss_key}/gviz/tq?sheet=Sheet1&tq=...
You can get the gid number of a sheet from the spreadsheet's url when it is open in your browser. More info here: https://developers.google.com/chart/interactive/docs/spreadsheets#Google_Spreadsheets_as_a_Data_Source
Note: data source url examples above are for new google sheets. If you are still using old sheets, the url format will be different: http://spreadsheets.google.com/a/google.com/tq?key=ABCDE&tq=.... The documentation link above still uses old sheets url format.
If you are querying your spreadsheet via QUERY() formula in another sheet, then just specify the name of the sheet you want to query in the data attribute of the function:
=QUERY('Example Data'!$A$2:$H$7, "select A where (B<>'Eng' and G=true) or (D > "&A2&")")

Resources