简体   繁体   中英

Read/Query Google Spreadsheet in JavaScript in HTML page

I am almost ashamed of asking this question since it must be super simple but I have looked everywhere on the web and I can't find it. The fact that Google recently changed the URL of its spreadsheets does not help.

Essentially, I am trying to read one value in a Google Spreadsheet and display it on my website. For instance, if I take this spreadsheet: https://docs.google.com/spreadsheets/d/1pzu6_-1rctgr_Zzr73Q1ZhJJrE0Ar8OH-uCaK50_V4w/edit#gid=0 . How do I show in my html page some like < p > Current Temperature is < script .... > ... < /script >< /p > ?

I already know how to use google.visualization and I am showing historical trends on my website, but I simply want to include the current temperature on a separate page. I figure we can do this in two ways, first by directly querying with a specific URL or by using an API. But I have no idea how to do this.

Any help would be greatly appreciated.

Thank you!

I'm sorry to see that this post gets little attention. I ended up using google.visualization to read the last value of the spreadsheet. I think it's a little overkill, but it works.

I think your best bet would be to use Google Apps Script. You embed this script within the spreadsheet and it runs automatically, even if you don't have it open. (Documentation: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet ). From what you've said above, I guess you want to do something like this:

  • When the Date Changes (You can set triggers in apps script)
  • Find the date in column A and grab the row number
  • Find the cell on that row in column B (Temp)
  • Get the value of that cell and pass it to your website.

Unfortunately I'm not sure how to solve your exact problem. Perhaps this will be a starting block or somebody else can take it from here. There is lots of documentation for apps script and there are plenty of Stack Overflow posts!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM