Sheet.getRange()
期望第一行,第二列,因此在您的x
调用中翻转y
和getRange()
。
function isempty(x,y) {
alert(SpreadsheetApp.getActiveSheet().getRange(x,y).isBlank());
return SpreadsheetApp.getActiveSheet().getRange(x,y).isBlank();
}
另外,请阅读Apps脚本Best Practices,并考虑改善脚本的方法。例如,在上面的代码段中,您执行了两次isBlank()
,但是只需要执行一次。
,
对于您打算做的事情,这是另一种方法。在我的代码中,我正在使用.getDataRange()
方法。这将获取工作表中的所有数据,然后使用for循环,您可以遍历所有行并使用 column 参数指定要从哪个列获取值
function nextopencell(column){
// Get the active spreadsheet and sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This represents ALL the data
var range = sheet.getDataRange();
var values = range.getValues();
// Build a new array to fill it with the desire data
var newColArray = [];
// Iterate over all rows
for (var i = 0; i < values.length; i++) {
// With the column we specify in what column we want to extract the data
if (values[i][column]) {
// fill array
newColArray.push(values[i][column]);
} else{
// Show what cells are empty
Logger.log("This is an empty cell at column " + (column+1).toString() + " and row " + (i+1).toString());
}
}
// This is the built array to fill a new column as you want
Logger.log(newColArray);
}
有关更多信息,您可以检查this。
本文链接:https://www.f2er.com/3126647.html