> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/appendix/gas/app/prototypes/app.sheet.prototype.md).

# app.sheet.prototype

[GAS](/web/appendix/gas.md) ⟩ [app](/web/appendix/gas/app.md) ⟩ [prototypes](/web/appendix/gas/app/prototypes.md) ⟩ sheet.prototype

{% tabs %}
{% tab title="🔴 主題" %}

* [💾 sheet.setValues()](/web/appendix/gas/app/prototypes/app.sheet.prototype/sheet.setvalues.md)
* [💾 sheet.delete()](/web/appendix/gas/app/prototypes/app.sheet.prototype/sheet.delete.md)
* getting [Range](/web/appendix/gas/classes/range.md)
  * sheet.range()
  * [💾 sheet.rangeByRect()](/web/appendix/gas/app/prototypes/app.sheet.prototype/sheet.rangebyrect.md) - 用 [RangeRect](/web/appendix/gas/custom-objects/rangerect.md) 來選 [Range](/web/appendix/gas/classes/range.md)
  * sheet.rangeListByRects()
* formatting [Range](/web/appendix/gas/classes/range.md)
  * [sheet.appendConditionalFormatRule()](/web/appendix/gas/app/prototypes/app.sheet.prototype/sheet.appendconditionalformatrule.md)
    {% endtab %}

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

```javascript
/**
 * write 2D data into sheet.
 * 
 * @example
 *   sheet.__proto__ = app.sheet.prototype
 *   sheet.setValues(data)
 */
app.sheet.prototype = {

  // 🔸 sheet.setValues(data)
  setValues(data, row=1, col=1){

    // ⬆️ require: Array.prototype.isMatrix (getter)
    if(!data.isMatrix) 
      throw new Error(`⛔️ app.sheet.prototype.setValues(): data 資料格式有問題，無法寫入試算表❗️`);

    // 資料表的「列數」與「欄數」
    let rows = data.length;
    let cols = data[0].length;

    // 寫入頁面
    this
      .getRange(row, col, rows, cols)
      .setValues(data);

    return this;   // for chaining
  },

  // ┌────────────────┐
  // │ getting Range  │
  // └────────────────┘

  // 🔸 sheet.range()
  range(row, col, rows, cols){
    const rng = this.getRange(row, col, rows, cols);
    Object.setPrototypeOf(rng, app.range.prototype);           // extend range
    return rng;
  },

  // 🔸 sheet.rangeByRect(rect: RangeRect)
  // require: RangeRect
  rangeByRect(rect){
    const range = this.getRange(...rect.toArray());
    range.__proto__ = app.range.prototype;           // extend range
    return range;
  },

  // 🔸 sheet.rangeListByRects(rects: [RangeRect])
  // require: RangeRect
  rangeListByRects(rects){
    const alNotations = rects.map(rect => this.rangeByRect(rect).getA1Notation());
    return this.getRangeList(alNotations);
  },

  // ┌────────────────────┐
  // │ formatting Ranges  │
  // └────────────────────┘

  // 🔸 sheet.appendConditionalFormatRule()
  appendConditionalFormatRule(rule){
    var rules = this.getConditionalFormatRules();
    rules.push(rule);
    this.setConditionalFormatRules(rules);
  },

};
```

{% endtab %}

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

* [Range](https://developers.google.com/apps-script/reference/spreadsheet/range) ⟩
  * [getA1Notation()](https://developers.google.com/apps-script/reference/spreadsheet/range#geta1notation) - 回傳類似 <mark style="color:yellow;">`"A1:E2"`</mark> 的字串。
* [RangeList](https://developers.google.com/apps-script/reference/spreadsheet/range-list#setBackground\(String\)) - collection of one or more [`Range`](https://developers.google.com/apps-script/reference/spreadsheet/range) instances <mark style="color:yellow;">**in the same sheet**</mark>.
* [Sheet](/web/appendix/gas/classes/sheet.md) ⟩&#x20;
  * [getRangeList(a1Notations)](https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangelista1notations)
  * [clear()](https://developers.google.com/apps-script/reference/spreadsheet/sheet?hl=en#clear)
  * [clear({ formatOnly: true, contentsOnly: true })](https://developers.google.com/apps-script/reference/spreadsheet/sheet?hl=en#clearoptions)
    {% endtab %}

{% tab title="👥 相關" %}

* [💡 custom prototypes](/web/appendix/gas/tips/custom-prototypes.md) for [Sheet](/web/appendix/gas/classes/sheet.md)
* [ConditionalFormatRule](/web/appendix/gas/classes/conditionalformatrule.md) - sheet can append conditional format rules.
* [Range](/web/appendix/gas/classes/range.md)
  {% endtab %}

{% tab title="⬆️ 需要" %}

* [arr.isMatrix](/web/js/val/builtin/arr/ext/arr.ismatrix.md)
  {% endtab %}

{% tab title="⬇️ 應用" %}

* [各班平均及前三名](/web/appendix/gas/projects/class-average.md) - 運用 <mark style="color:blue;">`sheet.setValues()`</mark>填各班平均、前三名表格。
* [不能補考名單](/web/appendix/gas/projects/no-make-up-exam.md)
* [app.sheetByName()](/web/appendix/gas/app/member/app.sheetbyname.md) - 讓回傳的 Sheet 直接擁有外掛。
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.sheet.prototype.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.
