在Google电子表格脚本中停止标准 [英] Stop criteria in google spreadsheet script
本文介绍了在Google电子表格脚本中停止标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
函数选择框(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 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);
返回应用程序;
$ b $ p
$ b在'if(item =='')'符合什么标准当电子表格中的单元格为空时,我应该使用此循环停止吗?
谢谢
解决方案
pre> 函数isNotEmpty(字符串)
{
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 +''; //检查一堆空白
if(''==(string.replace(/ ^ \ s * /,'').replace(/ \s\s * $ / ,'')))return false;
返回true;
}
I have this code that create a listbox with information from a spreadsheet:
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;
}
In the line with 'if (item == ' ')' what criteria should i use for this loop stop when a cell in Spreadsheet is empty?
Thank you
解决方案 I tend to use the following function of my library to check if a variable (string) is not empty (if that is what you mean) .
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;
}
这篇关于在Google电子表格脚本中停止标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文