[英]How to use Google visualization API to retrieve google spreadsheet cell value?
I'm trying to get the value of a cell on a google spreadsheet but it doesn't seem to work. 我正在尝试获取Google电子表格中单元格的值,但它似乎不起作用。
Here is my javascript code: 这是我的JavaScript代码:
<html>
<script>
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(loadChart);
function loadChart() {
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1sA7M5kG6Xo8YScD1Df38PIA_G0bvhGRdqoExXg0KJTs/edit#gid=0');
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var datatable = response.getDataTable();
var result = datatable.getValue(0,0);
document.getElementById('output1').value = result;
document.getElementById('output2').innerHTML = result;
document.getElementById('output3').textContent = result.toString();
}
</script>
</head>
<body>
Test 1: There are <input id="output1"> value <br>
Test 2: There are <p id="output2"> value </p>
<p> Test 3: There are <a id="output3"> </a> value </p>
</body>
The Spreadsheet url google spreadsheet 电子表格网址google电子表格
This is what I came up with: 这是我想出的:
<html>
<head>
<script type='text/javascript'>
window.onpageshow = function () {
google.load('visualization', '1', {
callback: function () {
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1sA7M5kG6Xo8YScD1Df38PIA_G0bvhGRdqoExXg0KJTs/gviz/tq?tqx=out:html&tq?gid=0&headers=0&range=A1:C');
query.send(displayData);
}
});
function displayData(response) {
numval = response.getDataTable().getValue(0,0);
document.getElementById('data').innerHTML = numval;
}
}
</script>
</head>
<body>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<div id="data"></div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.