正在搜索Google Spread Sheet API

时间:2012-09-09 17:30:30

标签: javascript html google-api spreadsheet

我正在尝试创建搜索,搜索我的Google电子表格。

在我的query.setQuery()中没有搜索我输入的搜索字符串。

表格也没有正确填充,

我制作了一些标签注释,以便我可以包含我的所有代码,因为堆栈溢出只能让我提交5个标签

感谢您的帮助

<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Example of Google Spreadsheet Data Visualisation</title>
</head>

<body>

<form id="form1" name="form1" method="post" onsubmit ="return drawVisualization()"> <label>
<input id="search" name="search" type="text" />
</label>
<label>
<input type="submit" />
</label>

</form>
<p>

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

function getSearch() { return form1.elements["search"].value;}

    function drawVisualization() {

      $search = getSearch();
 if ($search > ''){ $search = $search;} else { $search = '';}

 // alert($search);

      var query = new google.visualization.Query(
          '//My link to public google spread sheet');

      query.setQuery("SELECT A ,B, C  where upper(A) like upper('{$search}')  or upper(B) like upper('{$search}') order by A asc label A 'Product', B 'Manufacturer', C 'Category' ");


    //"SELECT guests FROM exp_freeform_entries WHERE ordid='{$_SESSION['eid']}' LIMIT 1");


      query.send(handleQueryResponse);
    }

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

      var data = response.getDataTable();

     visualization = new google.visualization.Table(document.getElementById('table'));
     visualization.draw(data, {legend: 'bottom'});

    }

    google.setOnLoadCallback(drawVisualization);
    </script>

   <div id="table"></div>

</div>

</body>
</html>

0 个答案:

没有答案