使用查询中的Google应用程序脚本创建表格 [英] Creating a table using google app script from a query

查看:88
本文介绍了使用查询中的Google应用程序脚本创建表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功通过查询我拥有的Google表格来创建Google图表。我试图通过查询相同的Google表格来创建表格,但我没有收到任何结果。我知道我做错了什么,但我不知道它是什么:/以下代码:

 << ; HTML> 
< head>
< script type =text / javascriptsrc =https://www.google.com/jsapi>< / script>
< script type =text / javascript>
google.load(visualization,'1',{packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable(){
var query = new google.visualization.Query(
'https://docs.google.com/spreadsheet/ccc?key=1ZxBkX5lTidV2LJvSJYjBQfILF3PlIYjeNgDqsHZoMqo&tq=select% 20D%2C%20S%2C%20T%2C%20U%20where%20D%3C%3E%22Avatar%22' );

query.send(handleQueryResponse);

$ b函数handleQueryResponse(响应){
if(response.isError()){
alert('Error in query:'+ response.getMessage() +''+ response.getDetailedMessage());
return;
}

var data = response.getDataTable();
var table = new google.visualization.Table(document.getElementById('table_div'));

var options = {'title':'Bass Naming',
'width':'927',
'height':'510'};

table.draw(data,options);
}
< / script>

< title>来自电子表格的数据< / title>
< / head>

< body>
< span id ='columnchart'>< / span>
< / body>
< / html>


解决方案


var table = new
google.visualization.Table(document.getElementById('table_div'));

您没有任何元素在你的html代码中 id =table_div,所以你不会看到你的数据表显示在你的页面中。

检查您的浏览器的JavaScript控制台是否存在您的网页中可能存在的任何其他错误。

此外,这是来自一般基本html应用程序的代码,还是来自HTML服务器脚本项目HTML服务器中的HTML文件的HTML代码?只是因为沙箱限制和Caja消毒,GAS HTML服务并不总是适合Google Visualization API。


I have successfully been able to create a google chart by querying a google sheet that I have. I'm trying to create a table by querying the same google sheet, but I'm not getting any results. I know I'm doing something wrong, but I'm not sure what it is :/ Here's the code below:

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable() {
  var query = new google.visualization.Query(
      'https://docs.google.com/spreadsheet/ccc?key=1ZxBkX5lTidV2LJvSJYjBQfILF3PlIYjeNgDqsHZoMqo&tq=select%20D%2C%20S%2C%20T%2C%20U%20where%20D%3C%3E%22Avatar%22');

  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }

  var data = response.getDataTable();
  var table = new google.visualization.Table(document.getElementById('table_div'));

var options = {'title':'Bass Naming',
                 'width':'927',
                 'height':'510'};

table.draw(data, options);
}
</script>

<title>Data from a Spreadsheet</title>
</head>

<body>
<span id='columnchart'></span>
</body>
</html>

解决方案

var table = new google.visualization.Table(document.getElementById('table_div'));

You do not have any element with id="table_div" in your html code, so you won't see you data table displayed in your page.

Check your browser's javascript console for any other errors you may have in your page.

Also, is this code from a general basic html application, or from an HTML file in Google Apps Script project, server by HTMLService? Just asking because GAS HTML Service does not always play well with Google Visualization API due to sandbox restrictions and Caja sanitization.

这篇关于使用查询中的Google应用程序脚本创建表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆