我正在使用JavaScript Google可视化API来查询电子表格的表格。如果我不指定特定的查询(或使用'select *'),而是使用query,则可以正常工作。setQuery('select…')the requesttid似乎丢失了:
代码:未捕获错误:缺少查询请求id: undefined
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(queryTable);
function queryTable() {
var query = new google.visualization.Query(
'https://docs.google.com/spreadsheets/d/129uqCEZksVwOSlqTYF7HVrnbOqD3HqPq-warEMvdur8/edit#gid=0');
query.setQuery('select Date, Time, Name, Type, Preference'); // remove this line and it works
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var numrows = data.getNumberOfRows();
var tableHtml = '<table width="320">';
for (var row=0; row < numrows; row++) {
var date = data.getValue(row, 0);
var time = data.getValue(row, 1);
var name = data.getValue(row, 2);
var type = data.getValue(row, 3);
var pref = data.getValue(row, 4);
tableHtml += '<tr><td>' + name + '</td><td>' + type + '</td><td>' + pref + '</td>';
}
tableHtml += '</table>';
$('#table').append(tableHtml);
}
测试电子表格可以在这里看到:https://docs.google.com/spreadsheets/d/129uqCEZksVwOSlqTYF7HVrnbOqD3HqPq-warEMvdur8/edit?usp=sharing
抱歉,如果这是一个新手问题,但似乎找不到解决方案。由于
您的查询无效,您使用列标签,但必须使用列标识符:
query.setQuery("select A,B,C,D,E ");