2013-07-09 6 views
0

Я пытаюсь загрузить значения из диапазона электронных таблиц в список. Однако я хочу только загрузить значения, имеющие красный цвет фона. Вот функция, с которой у меня возникают проблемы.Загрузить значения ячеек в ListBox на основе цвета фона ячейки

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

Ваше начало было не так уж плохо, но вы сделали несколько недоумений относительно того, что добавить и как добавить его.

здесь код рабочий (не проверено) с некоторыми комментариями, чтобы объяснить:

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 
} 
+0

Спасибо Serge. Теперь это отлично работает. – Manuel303

+0

ok, хорошо. Кажется, что вы забыли принять ответы на свои сообщения ... вот как работает этот форум: если вы считаете, что ответ полезен, вы принимаете его. Благодарю. –

+0

спасибо за ответы ;-) (Энрике и я) –

Смежные вопросы