2013-07-09 110 views
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; 
} 

回答

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

謝謝嗶嘰。這現在工作很好。 – Manuel303

+0

好,很好。似乎你忘記接受你的帖子上的答案......這就是這個論壇的工作原理:如果你認爲答案是有用的,那麼你接受它。謝謝。 –

+0

謝謝你的答案;-)(恩裏克和我) –

相關問題