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;
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;
}
4

1 回答 1

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
}
于 2013-07-09T19:10:24.747 回答