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!
Related
What I knew
is how to link data by
="SheetName!A2:B2" (same file, Differet Sheets)
or
=importrange("Url","sheetName!A2)(Different file)
all these require manual edditing
My Question:
If i have a list of these sheet name, or even it's Url,
How can i get dates from other sheets by using these SheetName or Url?
BTW:
i am trying to build a Table Menu for my Inovice system automatically
i had a file with 100+ sheet, every sheet has the same form, and i had looked up how to generate Sheetname list with url, but when i try to link (Using SheetNAme or Url as clue) to get the total sell amount/ client name / time, i counld't.
SAMPLE
https://docs.google.com/spreadsheets/d/1R67knSxkHD8v6ICIYJtb24pMwV_76HoKLDb-S79lzP4/edit#gid=0
thanks for reading and helping, my english expressing may not be precise ,sorry for that.
In G8, try
=indirect(C8&"!C6")
be sure that the layout of each tab is similar (not the case in your spreadsheet) to expand the formula
This URL: https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338
Trying to use IMPORTXML on google Sheets to pull in the price (119.99 as of today)
Using the following formula:
(via Google Developer Tab, right-click Copy XPath)
=IMPORTXML(https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338, "//*[#id='product_price']/text()")
Or
=IMPORTXML("https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338","//meta[#itemprop='price']/#content")
Or
=importxml(https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338, "//div[#class='pr__price']")
Plus a few other variations - Unfortunatley, they all come out as #N/A
Can anyone help me find the correct path?
It seems that in this case, when the URL is retrieved by IMPORTXML(), most values are included in head. When I tried this URL, body retrieved by IMPORTXML() was empty. So how about this workaround?
=REGEXEXTRACT(IMPORTXML(A1,"//head/*"),"(\d.+)INC")
Please put the URL of https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338 to the cell "A1" and put the formula to other cell.
In this workaround, the value you want is retrieved from the values retrieved from head.
Result:
Note:
I'm not sure whether this formula can be used for other URL. If you want to use this for other URL, please confirm the values and set the xpath and regex.
If you use Google Apps Script, I think that the value can be retrieved from the body of URL.
If this was not what you want, I'm sorry.
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.
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&")")
I'm having some problems with ImportXML in my Google Spreadsheet. I currently have two sheets, each with their own ImportXML, retireving (basically) the same data - the server providing the data has updated their feed service to require the use of a user-specific "key" in the URL to track who is retrieving what. Prior to this change, my ImportXML worked just fine. They are about to turn off the non-key feeds, and my spreadsheets are about to break.
In the first (working) sheet, this is the feed.
I can import the data sucessfully by using the following syntax in cell A1:
=importXML(ʺhttp://atilla.hinttech.nl/fseconomy/xml?id=18649&key=M3LRG43T&query=GroupLogByMonth&month=10ʺ,ʺ//GroupLogByMonthʺ)
In the new (non-working) sheet, the URL to the feed (including my user-specific "keys") is here.
I am unable to create a working importXML on this sheet. None of my attempted Xpath queries worked, except "*"; but that resulted in all elements being lumped into a single cell.
I have shared my spreadsheet file (link is in the comments below - I am unable to post more than 2 links) with each of these sheets so that the above examples can be seen and played with. Any advise on the non-working sheet would be wonderful.
In the new XML feed there is no tag "GroupLogByMonth". This might explain why your Xpath query won't return anything when you look for that.
Did the format of the XML change too, next to the new URL?