我正在处理一段代码,以按照" offset"中的值分组的已排序Google表格中创建行的命名范围。每行的列。我正在寻找一种更有效的方法来选择这些范围。以下是我目前的建议,感谢任何建议!
function nameRanges (input, sheet, ss, offset){
var maxrows = sheet.getMaxRows()
var numRows = input.getNumRows();
sheet.deleteRows(numRows+1, maxrows-numRows);
var sheetname = sheet.getName()
var numCol = input.getNumColumns();
for (var j = 2, x=2, y=3; i <=numRows -1, j <=numRows, x <=numRows ; x++, y++){
var jvalue = sheet.getRange(j,offset).getValue();
var xvalue = sheet.getRange(x,offset).getValue();
var yvalue = sheet.getRange(y,offset).getValue();
var start = j
if (xvalue != yvalue){
var rangesize = sheet.getRange(j, 1, (y-j) , numCol);
Logger.log("New NamedRange "+sheetname + jvalue +" created from "+ start + " to " +y);
ss.setNamedRange (sheetname + jvalue, rangesize);
rangesize.setBorder(true, true, true, true, false, false, "black", SpreadsheetApp.BorderStyle.SOLID)
j=y
}}
}