我正在编写下面的脚本(请记住,它还远未完成):
function Import() {
var dealCells = getRange('Deals');
var blank = new Array ("");
if (blank.indexOf(dealCells.getValue()) != -1) {
if (Browser.msgBox('You have not entered all the Deal IDs, do you want to continue anyway?', Browser.Buttons.YES_NO) == 'no') {
Browser.msgBox('Please fill in all the Deal IDs')
if (blank.indexOf(dealCells.getValue()) == -1) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Worksheet");
var cell = sheet.getRange(2,12);
cell.setValue("IMPORT");
}
}
}
}
我试图确定工作表中的A4:A23范围内是否有空单元格'时事通讯'。
如果有空单元格:会提示是/否消息框
答案 0 :(得分:0)
假设dealCells
为A4:A23
:
function Import() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('Newsletter');
// Get range values
var dealCells = sh.getRange("A4:A23").getValues()
// Flatten array for `indexOf()`
var blank = dealCells.join().split(',');
if (blank.indexOf("") != -1) { // Check if there is a blank cell
// If a blank cell exist
var response = Browser.msgBox('You have not entered all the Deal IDs, do you want to continue anyway?', Browser.Buttons.YES_NO)
// Handle the msgBox response
if (response == "yes") {
var value = Browser.msgBox('Please fill in all the Deal IDs')
} else { //response == no
...
}
} else { // no blank cell
...
}
...
}
修改您还可以getRangeByName():
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dealCells = ss.getRangeByName('Deals').getValues();