# range.contains()

[GAS](/web/appendix/gas.md) ⟩ [app](/web/appendix/gas/app.md) ⟩ [range](broken://pages/yBUzRclQF6ZBjZYXLBA9) ⟩ .contains()

{% tabs %}
{% tab title="💾 程式" %}

```javascript
// 🔸 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;
}
```

{% endtab %}

{% tab title="💈範例" %}

```javascript
// 
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();
}
```

![](/files/fU0u1Fj2jngxdUFxjwXP)
{% endtab %}

{% tab title="📘 手冊" %}

* [Sheets](https://developers.google.com/apps-script/reference/spreadsheet?hl=en) ⟩ [Range](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en) ⟩&#x20;
  * [.getRow()](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getrow)
  * [.getColumn()](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getcolumn)
  * [.getNumRows()](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getnumrows)
  * [.getNumColumns()](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getnumcolumns)
    {% endtab %}
    {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/appendix/gas/app/prototypes/app.range.prototype/range.contains.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
