2013-02-04 47 views
1

我有這樣的代碼是從電子表格創建信息的列表框:停止標準

function Selectbox(NameBox ,Row ,ID ,NameSheet ,NameCol) { 
    var sheet = SpreadsheetApp.openById(ID).getSheetByName(NameSheet); 
    var lastRow = sheet.getLastRow(); 
    var app = UiApp.getActiveApplication(); 
    var ListBox = app.createListBox().setWidth(125).setName(NameBox); 
    var ind = getColIndexByNamelink(NameCol, sheet); 
    ListBox.setVisibleItemCount(1); 
    for (var i = 2; i < lastRow + 1; i++) { 
    var Item = sheet.getRange(i, (ind * 1)).getValue(); 
    if (Item == ' ') 
     break; 
    else 
    ListBox.addItem(Item); 
    } 
    var grid = app.getElementById('grid'); 
    grid.setWidget(Row, 1, ListBox); 
    return app; 
} 

在符合「如果(項目==」「),」我應該用什麼標準當電子表格中的單元格爲空時,此循環會停止嗎?

謝謝

+2

在你的代碼中你在引號之間有一個空格。這不是一個空字符串。 – ScampMichael

+0

謝謝你是那個 –

+0

酷! '去過那裏了!'翻譯? – ScampMichael

回答

2

我傾向於使用我的庫下面的函數來檢查,如果一個變量(字符串)不爲空(如果這是你的意思)。

function isNotEmpty(string) 
{ 

    if(!string)    return false;   
    if(string == '')  return false; 
    if(string === false) return false; 
    if(string === null)  return false; 
    if(string == undefined) return false; 
    string = string+' '; // check for a bunch of whitespace 
    if('' == (string.replace(/^\s\s*/, '').replace(/\s\s*$/, ''))) return false;  
    return true;   
} 
+0

謝謝你,這非常有用 –