【发布时间】:2016-02-20 15:17:02
【问题描述】:
我正在尝试获取谷歌电子表格中单元格的值,但它似乎不起作用。
这是我的 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>
电子表格网址google spreadsheet
【问题讨论】:
-
您是否收到错误消息?这有帮助吗? -->
https://docs.google.com/spreadsheets/d/1sA7M5kG6Xo8YScD1Df38PIA_G0bvhGRdqoExXg0KJTs/gviz/tq?headers=1&tq=SELECT A -
嗨,是的。我收到“查询错误:请求超时”。还尝试使用您提供的链接及其相同的错误。
-
来自this question 的评论 -- 查询刚刚超时,因为一些返回的 JSON 代码包含一些空数据点
标签: javascript google-sheets google-visualization