range.contains()
GAS ⟩ app ⟩ range ⟩ .contains()
// 🔸 app.range.contains(superRange, subRange)
app.range.contains = function(superRange, subRange) {
// get first row #
let r11 = superRange.getRow();
let r21 = subRange.getRow();
if (r11 > r21) return false;
// get last row #
let r12 = r11 + superRange.getNumRows() - 1;
let r22 = r21 + subRange.getNumRows() - 1;
if (r12 < r22) return false;
// get first col #
let c11 = superRange.getColumn();
let c21 = subRange.getColumn();
if (c11 > c21) return false;
// get last col #
let c12 = c11 + superRange.getNumColumns() - 1;
let c22 = c21 + subRange.getNumColumns() - 1;
if (c12 < c22) return false;
return true;
}
//
function test_rangeContains() {
let tempA = app.range.byName('tempA');
let tempB = app.range.byName('tempB');
let tempC = app.range.byName('tempC');
let tempD = app.range.byName('tempD');
app.log(`A contais B: ${app.range.contains(tempA, tempB)}`); // false
app.log(`A contais C: ${app.range.contains(tempA, tempC)}`); // true
app.log(`A contais D: ${app.range.contains(tempA, tempD)}`); // true
app.log(`B contais A: ${app.range.contains(tempB, tempA)}`); // false
app.log(`B contais C: ${app.range.contains(tempB, tempC)}`); // false
app.log(`B contais D: ${app.range.contains(tempB, tempD)}`); // true
app.printLogs();
}
Last updated