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

在与'if(item =='')'一致时,当电子表格中的单元格为空时,我应该使用什么标准来停止此循环?

谢谢

4

1 回答 1

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;        
}
于 2013-02-04T18:32:59.403 回答