4

我正在尝试使用谷歌电子表格作为临时数据库。我已按照以下教程中的说明进行操作,一切正常

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

获取我在下面复制的数据以供参考的 jquery

我想知道是否有可能(使用相同或相似的代码),假设电子表格中有多个工作表一次只能查询一个。因此,例如,您可以运行以下代码,但仅适用于表 4。

我已经尝试在数字代码的末尾添加来自网络 URL 的工作表参考号(即#gid=1),所以

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

变成

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

但这不起作用,代码似乎只循环通过第一张纸

有人可以就此提出建议吗?

任何帮助深表感谢

<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>
4

2 回答 2

6

好的,我为任何感兴趣的人提供了一个解决方案,尽管它不像我希望的那样明智

感谢下面的博文

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

似乎特定工作表的 id 是 URL 的 /od6/ 部分,而 od6 是第一个默认工作表的默认名称

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

在上面的博客文章中,有一个示例说明如何在需要时找出特定工作表的 ID。它似乎没有一个干净的逻辑,但改变它会从特定的工作表中吐出数据,所以它可以工作。

于 2013-11-13T01:44:05.840 回答
2

I realize this is an old post, but I have been fighting this for a while. I made my own library to take care of this and I hope this saves someone many hours of research and playing with the google api. The general format is almost verbatim from the google documentation and I removed error checking to stay concise. What I could not find in the google documentation was how to query a tab that isn't the first one. I think this is what we are looking for here.

Based on what you already have, this should answer it.

table_name_here/gviz/tq?sheet=tab_name_here

As an example for all those that come after you:

https://docs.google.com/spreadsheets/d/17mbdvl1jVpqj42E3BSX34q9XUA2PbYubYKpVeypbHLA/gviz/tq?sheet=Sheet1 This could be used as the table_string in the code below.

'SELECT *' This could be used as the query_string in the code below.

Within context:

function gimmeATable(){ var query = new google.visualization.Query('table_string'); query.setQuery('query_string'); query.send(handleQueryResponse); }

function handleQueryResponse(response){ var data = response.getDataTable; drawTable(data); }

function drawTable(data){ var table = new google.visualization.Table(document.getElementById('div1')); table.draw(data, {showRowNumber: true}); }

And don't forget to include the google api as well as package type. For this you only need a table.

<script type="text/javascript" src="https://www.google.com/jsapi"></script> google.load("visualization", '1', {packages:['table']});

于 2015-02-04T05:22:39.620 回答