gpt4 book ai didi

javascript - 从 Google 表格循环

转载 作者:行者123 更新时间:2023-11-28 09:19:02 25 4
gpt4 key购买 nike

我正在尝试从 Google 表格中进行循环,从中得出 a0、a1、a2 等。我可以手动设置变量,但无法使循环正确。

google.load('visualization', '1', {
packages: ['gauge']
});
google.setOnLoadCallback(queryValue);

function queryValue() {
var query = new google.visualization.Query('https://spreadsheets.google.com/spreadsheet/tq?range=B22:B37&key=0AhCv9Xu_eRnSdFNhSzNQUFd3b1ZfRHgtQURINFpzeGc&gid=7');
query.send(function (response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();

//date label loop
for (var i = 0; i <= 15; i++) {
document.getElementById('b' + (i + 22)).innerHTML = data.getValue(i, 0);
console.log("i =" + b22)
}

});
queryValue1()
}

function queryValue1() {
var query = new google.visualization.Query('https://spreadsheets.google.com/spreadsheet/tq?range=A22:A37&key=0AhCv9Xu_eRnSdFNhSzNQUFd3b1ZfRHgtQURINFpzeGc&gid=7');
query.send(function (response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data1 = response.getDataTable();
var a1 = data1.getValue(0, 0);
var a2 = data1.getValue(1, 0);
var a3 = data1.getValue(2, 0);
var a4 = data1.getValue(3, 0);
var a5 = data1.getValue(4, 0);
var a6 = data1.getValue(5, 0);
var a7 = data1.getValue(6, 0);
var a8 = data1.getValue(7, 0);
var a9 = data1.getValue(8, 0);
var a10 = data1.getValue(9, 0);
var a11 = data1.getValue(10, 0);
var a12 = data1.getValue(11, 0);
var a13 = data1.getValue(12, 0);
var a14 = data1.getValue(13, 0);
var a15 = data1.getValue(14, 0);
var a16 = data1.getValue(15, 0);

queryValue3(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16);
});


}

function queryValue3(met1, met2, met3, met4, met5, met6, met7, met8, met9, met10, met11, met12, met13, met14, met15, met16) {
var query3 = new google.visualization.Query('https://spreadsheets.google.com/spreadsheet/tq?range=B2:B17&key=0AhCv9Xu_eRnSdFNhSzNQUFd3b1ZfRHgtQURINFpzeGc&gid=10');
query3.send(function (response) {
if (response.isError()) {
alert('Error in query3: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}

var data3 = response.getDataTable();

var m1 = data3.getValue(0, 0);
var m2 = data3.getValue(1, 0);
var m3 = data3.getValue(2, 0);
var m4 = data3.getValue(3, 0);
var m5 = data3.getValue(4, 0);
var m6 = data3.getValue(5, 0);
var m7 = data3.getValue(6, 0);
var m8 = data3.getValue(7, 0);
var m9 = data3.getValue(8, 0);
var m10 = data3.getValue(9, 0);
var m11 = data3.getValue(10, 0);
var m12 = data3.getValue(11, 0);
var m13 = data3.getValue(12, 0);
var m14 = data3.getValue(13, 0);
var m15 = data3.getValue(14, 0);
var m16 = data3.getValue(15, 0);

var red22 = "<span style='color:#ff0000'> ";
var yellow22 = "<span style='color:#FF9900'> ";
var green22 = "<span style='color:#009900'> ";

此代码查询 Google 表格,并在页面上绘制 16 个仪表,动态更改记录数据的月份,并且仪表上的标签会更改颜色以匹配仪表上的颜色(红色、黄色或绿色)。 This is the page

正如你所看到的,我还有一些改进的空间。我已经设法让一切正常工作,但我缩短了几个循环。

最佳答案

我认为返回一个数组比返回一个变量要有效得多。

类似这样的事情:

var a = [];
for (var z = 0; z <= 15; z++) {
a[z] = data1.getValue(z, 0);
}

要获取 a0、a1、a2 等的值,您只需使用 a[0]、a[1]、a[2] 等即可。

关于javascript - 从 Google 表格循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15262598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com