Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query specific sheets of a google spreadsheet

I am attempting to use a google spreadsheet as a temporary database. I have followed the instructions at the folowing tutorial and everything is working fine

http://www.alatechsource.org/blog/2012/05/using-the-google-spreadsheets-data-api-to-build-a-recommended-reading-list-code-words.h

The jquery that gets the data I have copied below for ref

I wondered if it would be possible (using the same or similar code), assuming there are multiple sheets within the spreadsheet to query just one at a time. So for example you could run the below code but only for say sheet 4.

I have tried adding sheet ref # from the web URL (i.e #gid=1) at the end of the numeric code so

"https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE/od6/public/values?alt=json-in-script&callback=?"

becomes

"https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE#gid=1/od6/public/values?alt=json-in-script&callback=?"

but this does not work, the code only seems to loop through the first sheet

Can anyone advise on this?

Any help is much appreciated

<script type="text/javascript"> 
$(document).ready(function() {  

//source file is https://docs.google.com/spreadsheet/ccc?    key=0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE   
$(function listBooks() {    

$.getJSON( "https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE/od6/public/values?alt=json-in-script&callback=?",

function (data) {   

    $('div#book-list').append('<ul class="items"></ul>');

    $.each(data.feed.entry, function(i,entry) { 

        var item = '<span style="display:none">' + entry.id.$t + '</span>'; 

        item += '<img src="http://covers.openlibrary.org/b/isbn/' + entry.gsx$isbn.$t + '-S.jpg"/>';

        item += '<span class="meta"><a href="http://www.worldcat.org/isbn/' + entry.gsx$isbn.$t + '">' + entry.title.$t + '</a>';   

        item += '<br/>Author: ' + entry.gsx$author.$t;  

        if (entry.gsx$notes.$t) {   

            item += '<br/>Description: ' + entry.gsx$notes.$t;  

        }   

        $('.items').append('<li>' + item + '</span></li>'); 

        });

    });

});

   });


   </script>
like image 926
Nick Avatar asked Feb 14 '23 17:02

Nick


1 Answers

Ok, I have a solution for anyone who is interested, although it is not as sensible as I would have hoped

Thanks to the below blogpost

http://damolab.blogspot.co.uk/2011/03/od6-and-finding-other-worksheet-ids.html

It seems that the id for specific sheets is the /od6/ part of the URL and od6 is the default name given to the first, default, sheet

"https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE/od6/public/values?alt=json-in-script&callback=?"

In the above blog post there is an example of how to find out the IDs of specific sheets if you need. There doesn't seem to be a clean logic to it but changing it will spit out the data from specific sheets so it works.

like image 120
Nick Avatar answered Feb 28 '23 09:02

Nick