简体   繁体   English

查询Google电子表格的特定表格

[英]Query specific sheets of a google spreadsheet

I am attempting to use a google spreadsheet as a temporary database. 我正在尝试将Google电子表格用作临时数据库。 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 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 获取我在下面复制的数据的jquery为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. 例如,您可以运行以下代码,但仅适用于表4。

I have tried adding sheet ref # from the web URL (ie #gid=1) at the end of the numeric code so 我尝试在数字代码的末尾从Web URL(即#gid = 1)添加sheet ref#

" https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE/od6/public/values?alt=json-in-script&callback= ?" 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= ?" 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>

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 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 似乎特定工作表的id是URL的/ od6 /部分,od6是第一个默认工作表的默认名称

" https://spreadsheets.google.com/feeds/list/0Ak0qDiMLT3XddHlNempadUs1djdkQ0tFLWF6ci1rUUE/od6/public/values?alt=json-in-script&callback= ?" 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. 在上面的博客文章中,有一个示例,说明如何根据需要找出特定工作表的ID。 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. 似乎没有一个干净的逻辑,但改变它将吐出特定表格中的数据,因此它的工作原理。

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. 我创建了自己的图书馆来处理这个问题,我希望这可以节省一些人花费数小时研究并使用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. https://docs.google.com/spreadsheets/d/17mbdvl1jVpqj42E3BSX34q9XUA2PbYubYKpVeypbHLA/gviz/tq?sheet=Sheet1这可以在下面的代码中用作table_string。

'SELECT *' This could be used as the query_string in the code below. 'SELECT *'这可以在下面的代码中用作query_string。

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. 并且不要忘记包括谷歌api以及包类型。 For this you only need a table. 为此你只需要一张桌子。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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