Google apps script 基于单元格背景颜色将单元格值加载到列表框中

Google apps script 基于单元格背景颜色将单元格值加载到列表框中,google-apps-script,Google Apps Script,我正在尝试将电子表格范围中的值加载到列表框中。但是,我只想加载具有红色背景色的值。这是我遇到问题的函数 function loadDupsMonday(e){ var app= UiApp.getActiveApplication(); var openss= SpreadsheetApp.openById(e.parameter.ttbox) var attlist= openss.getSheetByName('Client Duplicate'); app.getElementById('

我正在尝试将电子表格范围中的值加载到列表框中。但是,我只想加载具有红色背景色的值。这是我遇到问题的函数

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;
}
函数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();
变量c=[]

对于(var j=0;j来说,您的开始并不太糟糕,但您对添加什么以及如何添加感到困惑

下面是一个正在运行(未测试)的代码,其中有一些注释要解释:

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
}
函数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”);//确定只处理前100个单元格吗?
var background=range.getBackgrounds();//获取二维数组中的颜色
var data=range.getValues();//并获取二维数组中的数据
var c=[];//=收集要添加到列表框的项的空数组

对于(var j=0;JOK,很好),你似乎忘记了在你的帖子上接受答案…这个论坛就是这样工作的:如果你认为答案是有用的,那么你就接受它。谢谢。