我正在尝试将电子表格范围中的值加载到列表框中。但是我只想加载具有红色背景颜色的值。这是我遇到问题的功能。
function loadDupsMonday(e){
var app= UiApp.getActiveApplication();
var openss= SpreadsheetApp.openById(e.parameter.ttbox)
var attlist= openss.getSheetByName('Client Duplicate');
app.getElementById('dmonlbl').setVisible(true)
dlist=attlist.getLastRow()-1;
lastcol=attlist.getLastColumn();
range=attlist.getRange("B2:B100");
var background=range.getBackgrounds();
var c= []
for (var j=0;j<background; j++){
if (background[j] != "#00ff00"){
c++;}
app.getElementById('dupmon').addItem(background[j][0]).setVisible(true)
}
return app;
}
答案 0 :(得分:0)
你的开始并不是太糟糕,但是你对添加的内容以及如何添加它做了一些混乱。
这是一个有效的(未经测试的)代码,其中包含一些注释:
function loadDupsMonday(e){
var app= UiApp.getActiveApplication();
var openss= SpreadsheetApp.openById(e.parameter.ttbox)
var attlist= openss.getSheetByName('Client Duplicate');
app.getElementById('dmonlbl').setVisible(true)
dlist=attlist.getLastRow()-1; // I don't know if you need this elsewhere but in this example it is useless
lastcol=attlist.getLastColumn(); // same comment
range=attlist.getRange("B2:B100");// are you sure you want to handle only the 100 first cells ?
var background=range.getBackgrounds();//get colors in a 2D array
var data = range.getValues();// and get data in a 2D array
var c= [];// =empty array to collect items to add to the listBox
for (var j=0;j<background.length; j++){
if (background[j][0] != "#00ff00"){ // check the condition on "GREEN"
c.push(data[j][0]);//add data, not background
}
}
var listBox = app.getElementById('dupmon').setVisible(true);
for(var i in c){
listBox.addItem(c[i]);//add items in a 2cond loop
}
return app; // update UI
}